Save Word file as ". HTM" from excel vba

bos88

New Member
Joined
Oct 27, 2017
Messages
2
Hi all,
need a quick help. I am trying from Excel vba to open a word document (2010 version) and save it as a .htm format. I tried different solutions but nothing seems to work. Here is my code. It works without error but when I open the .htm file it is all gibberish. I want as well to keep this code with late binding.
Appreciate your input on this

Sub openExistingWordFile()
Dim oWord As Object
Set oWord = CreateObject(Class:="Word.Application")
oWord.Visible = True

oWord.Documents.Open Filename:="D:\Application\VBA\test.docx" ' OPEN AN EXISTING FILE.
oWord.Activate
oWord.ActiveDocument.SaveAs Filename:="D:\Application\VBA\test.htm", FileFormat:=wdFormatHTML
oWord.Quit
Set oWord = Nothing
End Sub



 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I want as well to keep this code with late binding.
Appreciate your input on this
But your code would not work with late-binding, since you must already have a Word reference set for things like wdFormatHTML to work. Merely declaring 'oWord As Object' doesn't magically turn it into late-binding code. Furthermore, according to the Word VBA Help, SaveAs doesn't take a FileFormat argument; you should use SaveAs2 for that.
 
Upvote 0
Thanks.
Actually, managed to solve my issue. Just had to change the code to "oWord.ActiveDocument.SaveAs Filename:="D:\Application\VBA\test", FileFormat:=8"
 
Upvote 0

Forum statistics

Threads
1,223,762
Messages
6,174,354
Members
452,558
Latest member
jswan83

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