R
Rick Roberts
I am using Late Binding for creating a word document from Access 2003. All
is well and good EXCEPT I am having difficulty with the following.
I am using bookmarks within a template to place data throughout the
document. One of the bookmarks is actually replaced with a Word table as
generated by the code below. The way it is coded the resulting table is not
formatted the same as if I used early binding. Specifically the resulting
table seems to be returned as a single column instead of the 5-8 columns as
the rst data would indicate.
The second problem is that I need to massage the resulting table by bolding
some rows and columns, modifying selected text etc. In the early binding I
use
Dim CellLoop as Cell
For Each CellLoop In .Rows(1).Cells
CellLoop.Select
‘ do some editing
Next Cellloop
For those of you familiar with Word /Late Binding you know “as Cell†isn’t
defined. I am not sure how to navigate through a table without using Word
specific code. Actually, I am sure that I have several problems in what I
have so far but I have searched online and haven’t found anything relating to
working with Word Tables and Late Binding. Anyone have any answers? Clues?
Comments? I really can use the help!
Thank you so much in advance for any assistance
*****************************************************
Dim objWordApp as Object
Set objWordApp = GetObject("", "Word.Application")
… code to open template document ~ nothing too special there
With
CreateTableFromRecordset(objWordApp.ActiveDocument.Bookmarks("RoomSchedule").Range, RcdSet)
' Apply formatting
.AutoFormat 33 'wdTableFormat3DEffects2
.AutoFitBehavior 2 'wdAutoFitWindow
Public Function CreateTableFromRecordset(BookmarkItem As Object, rst As
ADODB.Recordset) As Object 'Word.table
Dim objTable As Object 'Word.Table
Dim varData As Variant
' Get the data from the recordset
varData = rst.GetString()
' Create the table
With BookmarkItem
.InsertAfter varData
Set objTable = .ConvertToTable()
End With
Set CreateTableFromRecordset = objTable
Set objTable = Nothing
End Function
is well and good EXCEPT I am having difficulty with the following.
I am using bookmarks within a template to place data throughout the
document. One of the bookmarks is actually replaced with a Word table as
generated by the code below. The way it is coded the resulting table is not
formatted the same as if I used early binding. Specifically the resulting
table seems to be returned as a single column instead of the 5-8 columns as
the rst data would indicate.
The second problem is that I need to massage the resulting table by bolding
some rows and columns, modifying selected text etc. In the early binding I
use
Dim CellLoop as Cell
For Each CellLoop In .Rows(1).Cells
CellLoop.Select
‘ do some editing
Next Cellloop
For those of you familiar with Word /Late Binding you know “as Cell†isn’t
defined. I am not sure how to navigate through a table without using Word
specific code. Actually, I am sure that I have several problems in what I
have so far but I have searched online and haven’t found anything relating to
working with Word Tables and Late Binding. Anyone have any answers? Clues?
Comments? I really can use the help!
Thank you so much in advance for any assistance
*****************************************************
Dim objWordApp as Object
Set objWordApp = GetObject("", "Word.Application")
… code to open template document ~ nothing too special there
With
CreateTableFromRecordset(objWordApp.ActiveDocument.Bookmarks("RoomSchedule").Range, RcdSet)
' Apply formatting
.AutoFormat 33 'wdTableFormat3DEffects2
.AutoFitBehavior 2 'wdAutoFitWindow
Public Function CreateTableFromRecordset(BookmarkItem As Object, rst As
ADODB.Recordset) As Object 'Word.table
Dim objTable As Object 'Word.Table
Dim varData As Variant
' Get the data from the recordset
varData = rst.GetString()
' Create the table
With BookmarkItem
.InsertAfter varData
Set objTable = .ConvertToTable()
End With
Set CreateTableFromRecordset = objTable
Set objTable = Nothing
End Function