Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot get Word document saved in HTML format

Status
Not open for further replies.

kathryn

Programmer
Apr 13, 2000
776
US
Good morning, all.

I have written a VBScript to save an uploaded document as HTML for our Intranet. The code works fine; the file is found, saved with the .htm extension, and then displayed. The only problem is that all formatting is lost, such as font sizes and bolding!

I have looked in the object browser in Word to see what the value is for SaveAs HTML and I have recorded a macro to get the value. When I record a macro, I am given the constant 100, but all the posts I read say that the value is 8. Well I have tried both of these and all I get when the file is saved is the text, all the same size, with no formatting. This makes me think that I am not really getting an HTML format, just a document saved with the .htm extension, if you know what I mean.

Here is a snippet of the code using the value 8 for wdSaveAsHTML:

****BEGIN SNIPPET*****


'create an instance of Word'
Set objApp = CreateObject("Word.Application")

'open the document'
set objDoc = objApp.Documents.Open("c:\temp\" & dname)

if err<>0 then
MsgBox &quot;Can't open file!&quot;
objDoc.close
objApp.quit
exit sub
end if
err.clear


objApp.ActiveDocument.saveas &quot;c:\temp\&quot; & newFileName, 8
if err<>0 then
MsgBox &quot;Can't save file to temp directory!&quot;
objDoc.close
objApp.quit
exit sub
end if
err.clear

******END SNIPPET*******

One odd thing: When I go into the Object Browser for Word, and search for wdSaveFormat, HTML is not listed as one of the formats. However, I CAN save a document, with the proper formatting, manually using File -> SaveAs HTML from the menu??!!??

I am running Office 97 on a WinNT 4 server.

Has anyone else had this problem? Any ideas, war stories, references or resources would be appreciated. Kathryn


 
For archive purposes, here is the answer.

This is the code that must be used.

You CANNOT refer to Fileconverters(&quot;HTML&quot;) due to a documented bug in WD97:

***BEGIN CODE SNIPPET*****

'Get the file converter'
'This is necessary due to a bug in Word 97.'
' See KB article ID: Q162132'
for x = 1 to objApp.fileconverters.count
if objApp.fileconverters(x).ClassName=&quot;HTML&quot; then
fc=objApp.fileconverters(x).saveformat
end if
next

objApp.ActiveDocument.SaveAs &quot;c:\temp\&quot; & newFileName, fc
****END CODE SNIPPET*****
Kathryn


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top