Save Word Document as HTML via Excel VBA

strorg

Board Regular
Joined
Mar 27, 2002
Messages
112
I have some code that creates a MS Word document. I am able to save the document as rtf format using the following code:

Dim SaveAsName as String
.ActiveDocument.SaveAs _
Filename:=SaveAsName

I would like to use the code below (copied from a Word recorded macro) to save the file as HTML. My code bombs on:
FileFormat:= wdFormatHTML
saying variable not defined.

Dim SaveASHTML as String
.ActiveDocument.SaveAs Filename:=SaveAsHTML, FileFormat:= _
wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False

Any advice?

Regards...Tom
This message was edited by strorg on 2002-11-04 12:18
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The value of the constant wdFormatHTML is 8, so use that instead.

You cannot use constants if you are using late binding.
 
Upvote 0
Do you have a reference to Microsoft Word in your project? In the VBE, go to Tools-References, and select Microsoft Word X.x Object Library.

Let me know if it works,

Russell
 
Upvote 0
Adding the reference did the trick. Will each user have to do this or is that embedded in my code now?

Thanks much...Tom
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top