• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1258
  • Last Modified:

Extract html from word document using vba script

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.
  • 2
  • 2
1 Solution
You can save a Word document in HTML format.
cteakleAuthor Commented:
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
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
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
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
cteakleAuthor Commented:
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.
You're welcome Chris, that's quite a challenge you have taken on, all the best with it
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now