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
Replace Cell with Object

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> 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.
[quoted text clipped - 21 lines]
> 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!
[quoted text clipped - 9 lines]
>
> With
CreateTableFromRecordset(objWordApp.ActiveDocument.Bookmarks("RoomSchedule")
.Range, RcdSet)
> ' Apply formatting
> .AutoFormat 33 'wdTableFormat3DEffects2
[quoted text clipped - 15 lines]
> Set objTable = Nothing
> End Function
Rick Roberts - 22 Nov 2005 17:50 GMT
Thanks for getting back to me so quickly. It does seem that defining it as
an object does work. I am sure I tried it before but hey, it was early.
I am still having the problem of the resulting table lumping all my data for
the row into a single column. Which is probably why the my Cell logic wasn't
working as I thought.
Any ideas?
At the bottom of your response you had
"CreateTableFromRecordset(objWordApp.ActiveDocument.Bookmarks("RoomSchedule")..Range, RcdSet)"
Was there a message in that? the only didifference that I could detect was
a '..' before Range which is an incorrect syntax
Again thanks for your input!
> Replace Cell with Object
>
[quoted text clipped - 66 lines]
> > Set objTable = Nothing
> > End Function
Douglas J. Steele - 22 Nov 2005 23:17 GMT
Sorry, all I typed was the 4 words "Replace Cell with Object". Any other
text was yours.
I don't really have any suggestion, other than try declaring a variable as
an object, setting it to the function, and using With that variable, rather
than With the function.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Thanks for getting back to me so quickly. It does seem that defining it
> as
[quoted text clipped - 96 lines]
>> > Set objTable = Nothing
>> > End Function