Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Converting HTML to Text under program control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RayS - 05 Aug 2005 22:59 GMT
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
Jezebel - 06 Aug 2005 00:14 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.