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
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
The value of the constant wdFormatHTML is 8, so use that instead.

You cannot use constants if you are using late binding.
 

Russell Hauf

MrExcel MVP
Joined
Feb 10, 2002
Messages
1,611
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
 

strorg

Board Regular
Joined
Mar 27, 2002
Messages
112
Adding the reference did the trick. Will each user have to do this or is that embedded in my code now?

Thanks much...Tom
 

Russell Hauf

MrExcel MVP
Joined
Feb 10, 2002
Messages
1,611
If they are using the same workbook (or a copy), the references will stay...
 

Watch MrExcel Video

Forum statistics

Threads
1,122,511
Messages
5,596,581
Members
414,079
Latest member
Frills

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
Top