Solved

Extract html from word document using vba script

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

895 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

18 Experts available now in Live!

Get 1:1 Help Now