| | |
vb and msword
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2006
Posts: 30
Reputation:
Solved Threads: 0
i have the following code, however, the table that is created always starts at the begining of the document. so none of the text written beforehand can be seen. i also dont know how to write things after the table.
anyone willing and able to help?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub wrd2() Dim c As Long Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim wrdTbl As Word.Table Dim wrdRange As Word.Range Set wrdApp = New Word.Application Set wrdDoc = wrdApp.Documents.Add Set wrdRange = wrdDoc.Range(Start:=0, End:=0) r = flxItems.Rows c = flxItems.Cols Set wrdTbl = wrdDoc.Tables.Add(wrdRange, r, c) With wrdApp .Visible = True .ActiveDocument.SaveAs App.Path & "\invoices\" & invoiceID & ".doc" .Selection.Font.Name = "Arial" .Selection.Font.Size = 12 .Selection.TypeText Text:="Customer Name : " & txtCustomerName & vbNewLine .Selection.TypeText Text:="Staff ID : " & lblStaffID & vbNewLine .Selection.TypeText Text:="Invoice Date : " & currDate & vbNewLine .selectionTypeText Text:="Invoice Number : " & invoiceID & vbNewLine & vbNewLine & vbNewLine End With If flxItems.Rows = 0 Or flxItems.Rows = 1 Then Exit Sub r = flxItems.Rows c = flxItems.Cols With flxItems For r = 1 To .Rows For c = 1 To .Cols wrdTbl.Cell(r, c).Range.Text = .TextMatrix(r - 1, c - 1) Next c Next r End With With wrdTbl .Borders(wdBorderTop).LineStyle = wdLineStyleNone .Borders(wdBorderLeft).LineStyle = wdLineStyleNone .Borders(wdBorderBottom).LineStyle = wdLineStyleNone .Borders(wdBorderRight).LineStyle = wdLineStyleNone End With wrdApp.ActiveDocument.Save wrdApp.Quit False End Sub
There are some issues that you need to address to position the TABLE in MSWord from VB. You'd have to enumerate the Table and
Public Enum as wdTablePosition (or something like that)
Also you can try this. Because you didn't include other TAGS some items were changed so that I could get it to work.
This puts the ID/NAME/INVOICEID information at the bottom of the table.
You were lucky I was working on some Word/Excel/VB6 interoperability issues this week.
Because I am using Word2000, I didn't have some of the options.. such as .TextMatrix etc
Hope that helps somewhat
Public Enum as wdTablePosition (or something like that)
Also you can try this. Because you didn't include other TAGS some items were changed so that I could get it to work.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub wrd2() Dim InvoiceID As Integer '*********Added Code ************** Dim r As Long '********was missing from my copy******** Dim c As Long Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim wrdTbl As Word.Table Dim wrdRange As Word.Range InvoiceID = 7755 '*********Added Code to have an Inv ID# ************** Set wrdApp = New Word.Application Set wrdDoc = wrdApp.Documents.Add Set wrdRange = wrdDoc.Range(Start:=0, End:=0) r = InputBox("Enter Number of Rows", "Row Count") '***Added Code to get a ROW***** c = InputBox("Enter Number of Columns", "Columns") '***Added Codeto get a COL****** 'r = flxItems.Rows 'c = flxItems.Cols With wrdApp .Visible = True .ActiveDocument.SaveAs App.Path & "\invoices\" & InvoiceID & ".doc" .Selection.Font.Name = "Arial" .Selection.Font.Size = 12 .Selection.TypeText Text:="Customer Name : " & "JOE" & vbNewLine 'txtCustomerName & vbNewLine .Selection.TypeText Text:="Staff ID : " & "777777" & vbNewLine ' lblStaffID & vbNewLine .Selection.TypeText Text:="Invoice Date : " & Format(Now(), "mmm dd yyyy") & vbNewLine 'currDate & vbNewLine .Selection.TypeText Text:="Invoice Number : " & InvoiceID & vbNewLine & _ vbNewLine & vbNewLine '*********Corrected Code had a period missing ************** .Selection.EndOf wdParagraph, wdExtend End With Set wrdTbl = wrdDoc.Tables.Add(wrdRange, r, c) If wrdTbl.Rows.count = 0 Or wrdTbl.Rows.count = 1 Then Exit Sub 'flxItems.Rows = 0 Or flxItems.Rows = 1 Then Exit Sub r = wrdTbl.Rows.count '****Corrected Code (no flxItems here)******* 'flxItems.Rows c = wrdTbl.Columns.count '***Corrected Code (no flxItems here)**** 'flxItems.Cols With wrdTbl For r = 1 To .Rows.count For c = 1 To .Columns.count wrdTbl.Cell(r, c).Range.Text = "this text" ' ***(No .TextMatrix here) > .TextMatrix(r - 1, c - 1) Next c Next r .Borders(wdBorderTop).LineStyle = wdLineStyleNone .Borders(wdBorderLeft).LineStyle = wdLineStyleNone .Borders(wdBorderBottom).LineStyle = wdLineStyleNone .Borders(wdBorderRight).LineStyle = wdLineStyleNone End With 'With wrdTbl ' .Borders(wdBorderTop).LineStyle = wdLineStyleNone ' .Borders(wdBorderLeft).LineStyle = wdLineStyleNone ' .Borders(wdBorderBottom).LineStyle = wdLineStyleNone ' .Borders(wdBorderRight).LineStyle = wdLineStyleNone 'End With wrdApp.ActiveDocument.Save wrdApp.Quit False End Sub
This puts the ID/NAME/INVOICEID information at the bottom of the table.
You were lucky I was working on some Word/Excel/VB6 interoperability issues this week.
Because I am using Word2000, I didn't have some of the options.. such as .TextMatrix etc
Hope that helps somewhat
•
•
Join Date: Feb 2006
Posts: 30
Reputation:
Solved Threads: 0
ah thanks, i meant to say i solved the problem but i must have forgot.
in the end i was able to get the company information to display top centre, the invoice details underneath, to the right, the list of items in the centre and the payment information at the bottom on the right.
what i had to do was change the following:
on the table, instead of assigning the actual value of Range. using the following code, anything text can be inputted, followed by the table. i used this.
this code was used to navigate to the final cell and go to the next line. allowing tet to be inputted after the table.
thanks for replying though.
in the end i was able to get the company information to display top centre, the invoice details underneath, to the right, the list of items in the centre and the payment information at the bottom on the right.
what i had to do was change the following:
on the table, instead of assigning the actual value of Range. using the following code, anything text can be inputted, followed by the table. i used this.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Set wrdRange = wrdApp.Selection.Range r = flxItems.Rows c = flxItems.Cols Set wrdTbl = wrdDoc.Tables.Add(wrdRange, r, c) If flxItems.Rows = 0 Or flxItems.Rows = 1 Then Exit Sub r = flxItems.Rows c = flxItems.Cols With flxItems For r = 1 To .Rows For c = 1 To .Cols wrdTbl.Cell(r, c).Range.Text = .TextMatrix(r - 1, c - 1) Next c Next
this code was used to navigate to the final cell and go to the next line. allowing tet to be inputted after the table.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
wrdApp.Selection.MoveRight Unit:=wdWord, Count:=7, Extend:=wdExtend 'move right to 7th column (outside the table) wrdApp.Selection.MoveDown Unit:=wdLine, Count:=r + 1 'go to last row wrdApp.Selection.MoveDown Unit:=wdLine ' got to next line
thanks for replying though.
![]() |
Similar Threads
- Adding a picture within msword (C#)
- Open MSword document from a web site (IT Professionals' Lounge)
- Lost some of WIndows/Office (Windows 95 / 98 / Me)
- Problem Downloading large files (ASP)
- Reading MSWord Document through an ASP Statement (ASP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Massage box in VB
- Next Thread: Huge flat file
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





