# Save Word file as ". HTM" from excel vba



## bos88 (Oct 27, 2017)

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



_


----------



## Macropod (Oct 27, 2017)

bos88 said:


> 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.


----------



## bos88 (Oct 29, 2017)

Thanks.
Actually, managed to solve my issue. Just had to change the code to "_oWord.ActiveDocument.SaveAs Filename:="D:\Application\VBA\test", FileFormat:=8_"


----------

