?
Solved

Extract html from word document using vba script

Posted on 2013-02-05
5
Medium Priority
?
1,197 Views
Last Modified: 2013-02-08
Hi
I am developing a little email database in msaccess 2010.  I want the users to be able to create their formatted message using word.  The rich text formatted memo type is not powerful enough for the users who want to be able to insert tables etc.

I then want to get the text from the word document and place that into a memo field in my mail table that will form the html part of an email.  I am using Ostrosoft SMTP Component to create the messages.  

The little database that I have been using so far has worked OK, but the users are getting sick of not having the full formatting capability of Word.

I have inserted an OLE field and linked that field onto my email form.  Now I just want to get the actual data out of that word document form.

Any suggestions / pointers would be gratefully received.
0
Comment
Question by:cteakle
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38854236
You can save a Word document in HTML format.
0
 

Author Comment

by:cteakle
ID: 38854488
Hi Graham
I just need the code to run from with access to save a word document as html document.
.I will then be able to parse that document and add the text to my email body field
Chris
0
 
LVL 16

Accepted Solution

by:
terencino earned 2000 total points
ID: 38854778
Even the most basic Word document saved as HTML has about 1000 lines of CSS/html code, most of it unneeded, but it makes parsing difficult and conversions to and from Word a nightmare. I think Outlook and Word html is slightly different to normal html as well which might make some of the fonts & styles etc come out differently. However, if you want to go down that path then you should be able to use some office automation  to open the Word doc then save as html, then open the Word html file as a TextStream using FileSystemObject, as a single object or line by line for processing. Just add a reference to Microsoft Scripting Runtime in your Access module and start experimenting with it.
Hope that helps
...Terry
Office Automation to open Word
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open("full_path_filename_ext")
wDoc.SaveAs [filename] [fileformat] have to hunt these down
wDoc.Close
Set wDoc = Nothing
Set wApp = Nothing

Open in new window

Processing the HTML file
Here are some pointers...
Using the FileSystemObject to Read Text Files
0
 

Author Closing Comment

by:cteakle
ID: 38869945
Hi Terencino
Sorry it took so long for me to get back to this question.  Your code did exactly what I asked.  I havent quite got there though.  I am still having trouble with the formatting of the message.  I can get a table happily into the message, but the other formatting does not display as expected - but that is another whole different issue.
Thank you so much for your help.
Chris
0
 
LVL 16

Expert Comment

by:terencino
ID: 38870029
You're welcome Chris, that's quite a challenge you have taken on, all the best with it
...Terry
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question