Word Table Formatting ~ Late Binding

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
 
D

Douglas J Steele

Replace Cell with Object

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Rick Roberts said:
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)
 
R

Rick Roberts

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!

:
 
D

Douglas J. Steele

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top