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
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
>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
[quoted text clipped - 23 lines]
> wrdApp.Quit SaveChanges:=False 'Quit Word with no more saves
> Set wrdApp = Nothing 'Clear Memory
RayS - 06 Aug 2005 01:03 GMT
That was the problem. Thank you very much.
> 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
[quoted text clipped - 30 lines]
> > wrdApp.Quit SaveChanges:=False 'Quit Word with no more saves
> > Set wrdApp = Nothing 'Clear Memory