Converting HTML to Text under program control

R

RayS

I need to convert HTML files to clean TXT files with line breaks. I tested
Word manually and it has this feature so I am trying to call that from within
VB6. I have written the following code which works except the destination
file format is always Word's default. Apparently the "fileformat" function of
the SaveAs line has something wrong but I need help determining what the
problem is? Any help would be appreciated.

Dim wrdApp As Object
Dim wrdDoc As Object
Dim strDocToOpen As String
Dim strDocToSave As String

strDocToOpen = "C:\Documents and Settings\Ray Smith\Junk\HTML test.htm"
strDocToSave = "C:\Documents and Settings\Ray Smith\Junk\HTML test.txt"

Set wrdApp = CreateObject("Word.Application")
wrdApp.WordBasic.DisableAutoMacros 'Disable any Macros
Set wrdDoc = wrdApp.Documents.Open(strDocToOpen) 'Open document
wrdDoc.SaveAs FileName:=strDocToSave, FileFormat:=wdFormatTextLineBreaks



wrdDoc.Close SaveChanges:=False 'Close the document
Set wrdDoc = Nothing 'Clear Memeory
wrdApp.WordBasic.DisableAutoMacros 0
wrdApp.Quit SaveChanges:=False 'Quit Word with no more saves
Set wrdApp = Nothing 'Clear Memory
 
J

Jezebel

You're apparently using late binding (ie, not adding the Word object library
to your project) -- in which case, VB won't know what wdFormatTextLineBreaks
means. The value is 3, which you can add as a literal or re-define as your
own constant.

wrdDoc.SaveAs FileName:=strDocToSave, FileFormat:=3
 
R

RayS

That was the problem. Thank you very much.

Jezebel said:
You're apparently using late binding (ie, not adding the Word object library
to your project) -- in which case, VB won't know what wdFormatTextLineBreaks
means. The value is 3, which you can add as a literal or re-define as your
own constant.

wrdDoc.SaveAs FileName:=strDocToSave, FileFormat:=3
 

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