Solved

Extract html from word document using vba script

Posted on 2013-02-05
5
810 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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now