Reading data with HTML Tags from Database

C

Chris

I want to use a WORD Template and VBA to read data from a
database and dynamically build the WORD Doc. The data
from the database contains HTML Tags. I want the data to
be appear as "rendered" when I view the WORD Doc.
 
D

Doug Robbins - Word MVP

Hi Chris,

The following code in a macro would delete the tags and apply bold
formatting to the text between the tags:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\<(STRONG\>)(*)\</\1",
MatchWildcards:=True, ReplaceWith:="\2", Wrap:=wdFindContinue,
Forward:=True) = True
Selection.Range.Font.Bold = True
Loop
End With

See the article "Finding and replacing characters using wildcards" at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

for and explanation of what the FindText string means.

You will need a similar routine to apply whatever other formatting is
required by other tags.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Chris Richardson

Thanks for this response.

So, are you saying that for everything, the HTML Tables,
Horizontal Lines, Bullet and Number List, that I would
have to loop through and convert using the approach
mentioned below? Wow!

I was hoping for something simpler. I'm afraid that I
will not catch all of the HTML tags that are possible to
come through. Also, I wonder if the original look/fill
will be regained.

I read in a seperate post about someone using some code
like:

wrdApp.Documents.Open FileName:="C:\Docs\skeletal.doc",
Format:=wdOpenFormatHTML

I'm not sure what the "FormatHTML" does. Can you
elaborate on this please? Otherwise, can you advise on
any other alternative to making WORD render HTML (the way
that the IE Browser does).

Thanks in advance for taking the time to respond.
 
W

Word Heretic

G'day "Chris Richardson" <[email protected]>,

I'd probably write the whole damn lot to a HTML file using File Open
statements and the like.

You can then open that HTML file and have it render.

Thanks for this response.

So, are you saying that for everything, the HTML Tables,
Horizontal Lines, Bullet and Number List, that I would
have to loop through and convert using the approach
mentioned below? Wow!

I was hoping for something simpler. I'm afraid that I
will not catch all of the HTML tags that are possible to
come through. Also, I wonder if the original look/fill
will be regained.

I read in a seperate post about someone using some code
like:

wrdApp.Documents.Open FileName:="C:\Docs\skeletal.doc",
Format:=wdOpenFormatHTML

I'm not sure what the "FormatHTML" does. Can you
elaborate on this please? Otherwise, can you advise on
any other alternative to making WORD render HTML (the way
that the IE Browser does).

Thanks in advance for taking the time to respond.

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 
C

Chris Richardson

Thanks for this reply. In fact, that is one route that
I've tried. The only problem with that is that I was
actually counting on the paganation, header, and footer
features from WORD.

I'm now considering letting the feed go into WORD - with
the HTML tags showing. Then, CTRL-A, copy/pasting the
results to Frontpage to get everything rendered.

Any other suggestions are appreciated.

Thanks again.


-----Original Message-----
G'day "Chris Richardson"
 

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