Sending colours / styles as well as text to bookmarks

Y

Yobbo

Hi All

Don't know how to best explain this, so I hope my ramble makes sense!!

Basically I've done a VB / Access DB app, which sends data to a Word Doc
template using a Word object reference and Bookmarks for the actual
placement.

How I've done it is get all the relevant data into an array and then poke
these values into the relevant bookmarks. In essence I have a word doc with
one big table on it and a bookmark in each cell of the table. I run through
the bookmarks and drop in the text (actually pupil names) where appropriate.

This all works fine apart from one thing. I need to apply formatting to
these pupil names such as background colour, text colour, bold, italic,
underline, etc and this formatting can be unique for each name.

Because you might have say 9 names (carriage return after each so they
appear on a line by themselves) in 1 cell and each of these names might have
different colouring/styling I can't do a simple blanket formatting in the
cell as a sort of 2nd pass after the text is in. I really need the ability
to do something like HTML, eg:

<redbg> & strPupilName1 & <redbg>
<bold> & strPupilName2 & <bold>
etc... etc...

or something to that effect.

Is this possible in the VBA / object ref method that I'm using or have you
got to go the:

ActiveDoc......background.color = red << I know the syntax is probably
wrong haven't looked it up
now poke the one pupil name onto the bookmark
ActiveDoc......background.color = black << I know the syntax is probably
wrong haven't looked it up
ActiveDoc......background.style = bold << I know the syntax is probably
wrong haven't looked it up
now poke the 2nd pupil name onto the bookmark
etc... etc...

Any ideas?

Thanks
 
D

Doug Robbins - Word MVP

As each name is followed by a carriage return, there will be one name to a
paragraph and you can there for apply the styling that you want to the Range
of each paragraph. For example:

Dim i As Long, j As Long, k As Long, n As Long
With ActiveDocument.Tables(i).Cell(j, k).Range.Paragraphs(n)
.Shading.BackgroundPatternColor = wdColorBlue
.Range.Font.Color = wdColorWhite
.Range.Font.Bold = True
.Range.Font.Italic = True
'etc
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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