From Visual Basic 6.0:
Create a document(word 9.0) that has a table (at the 17th line of the document with 4 columns) in it to receive a varying number of records (hence, I will build it dynamically with a loop of my recordset).
At this point I am just experimenting with the Word Objects as they are new to me. While my code may be worth ignoring completely at this point I have included my experimentation below. I think that I have definite issues understanding the use of selection and range:
I thought I was moving on the right track with this until I tryed to move the table down to line 17, and then my text no longer inserts in a cell but at the top of the document. Any assistance would be appreciated.
-----------------------------------------------------
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim WordTable As Word.Table
Dim WordColumn As Word.Column
Dim WordRow As Word.Row
Private Sub Command1_Click()
Set WordObj = Nothing
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open("C:\doc2.doc") 'Open the document
Set WordRange = WordDoc.Range(Start:=0, End:=0)
WordObj.Visible = True
With WordRange
.InsertBefore ("Document Statistics")
.Font.Name = "Veranda"
.Font.Size = 16
.InsertParagraphAfter
.InsertParagraphAfter
.SetRange Start:=WordRange.End, _
End:=WordRange.End
End With
WordDoc.Range(Start:=0, End:=0).Bold = True
Set WordTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Item(2).Range, 2, 4, wdWord9TableBehavior, wdAutoFitFixed)
Set WordRow = WordTable.Rows.Add(BeforeRow:=WordTable.Rows(1))
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
WordDoc.Tables(1).Cell(1, 1).Select
WordRange = Selection.Range
WordRange.Text = "test"
WordRange.Move Unit:=wdCell
WordRange.Text = "test"
WordRange.Move Unit:=wdCell
WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
WordRange.Move Unit:=wdRow
WordRange.Text = "test"
WordRange.Move Unit:=wdCell
WordRange.Text = "test"
End Sub
------------------------------------------------------------------------------------
Create a document(word 9.0) that has a table (at the 17th line of the document with 4 columns) in it to receive a varying number of records (hence, I will build it dynamically with a loop of my recordset).
At this point I am just experimenting with the Word Objects as they are new to me. While my code may be worth ignoring completely at this point I have included my experimentation below. I think that I have definite issues understanding the use of selection and range:
I thought I was moving on the right track with this until I tryed to move the table down to line 17, and then my text no longer inserts in a cell but at the top of the document. Any assistance would be appreciated.
-----------------------------------------------------
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim WordTable As Word.Table
Dim WordColumn As Word.Column
Dim WordRow As Word.Row
Private Sub Command1_Click()
Set WordObj = Nothing
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open("C:\doc2.doc") 'Open the document
Set WordRange = WordDoc.Range(Start:=0, End:=0)
WordObj.Visible = True
With WordRange
.InsertBefore ("Document Statistics")
.Font.Name = "Veranda"
.Font.Size = 16
.InsertParagraphAfter
.InsertParagraphAfter
.SetRange Start:=WordRange.End, _
End:=WordRange.End
End With
WordDoc.Range(Start:=0, End:=0).Bold = True
Set WordTable = WordDoc.Tables.Add(WordDoc.Paragraphs.Item(2).Range, 2, 4, wdWord9TableBehavior, wdAutoFitFixed)
Set WordRow = WordTable.Rows.Add(BeforeRow:=WordTable.Rows(1))
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext
WordDoc.Tables(1).Cell(1, 1).Select
WordRange = Selection.Range
WordRange.Text = "test"
WordRange.Move Unit:=wdCell
WordRange.Text = "test"
WordRange.Move Unit:=wdCell
WordTable.Rows.Add BeforeRow:=WordTable.Rows(1)
WordRange.Move Unit:=wdRow
WordRange.Text = "test"
WordRange.Move Unit:=wdCell
WordRange.Text = "test"
End Sub
------------------------------------------------------------------------------------