Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

Sending colours / styles as well as text to bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yobbo - 03 Aug 2007 20:13 GMT
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
old man - 03 Aug 2007 21:04 GMT
Hi,

Assuming there is a bookmark with the name "t2" this will format the range
associated with the bookmark as bold and with the color blue:

With ActiveDocument.Bookmarks("t2").Range.Font
   .Bold = True
   .Color = wdColorBlue
End With

You may want to set up style and apply the style to a range associated with
a bookmark.

Old Man

> Hi All
>
[quoted text clipped - 41 lines]
>
> Thanks
Doug Robbins - Word MVP - 03 Aug 2007 21:53 GMT
Also see response in vba.beginners newsgroup.

Please do not post the same question separately to more than one newsgroup,
rather, if you are not sure which is the best newsgroup, put the ones that
you think may apply in the header of the message.

If you do that a response in one newsgroup will also appear in the other
newsgroup(s) to which you have posted that question so someone seeing your
post in one of those newsgroups will also see that it has been answered.

As a beginner, you are forgiven this one time.

Signature

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

> Hi All
>
[quoted text clipped - 47 lines]
>
> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.