-
Word to HTML conversion
In Word there is a menu option Save as HTML..., under File. I've been asked to include this functionality in a programm i've written. So I referenced the MS Word 8.0 Object library, and I expected to find this SaveAsHtml functionality in there :confused: , but I can't seem to find it in the Object Browser. There is a SaveAs method for a Document object, but there is no HTML format available. Am I missing something, or is there an other way?
Rick
-
From Using the Macro Recorder in Word it looks like it is a parameter of save as. This is the code I got when saving doc1 as a web page
ActiveDocument.SaveAs FileName:="Doc1.htm", FileFormat:=wdFormatHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveWindow.View.Type = wdWebView
-
..nope
thanx for your reply, but...
This doesn't work from VB. It gives me a variable not defined error on wdFormatHTML.
Any1 else???
-
Well admittedly I am referencing the 9.0 Object Library but the following works fine for me.
Dim X As Object
Set X = CreateObject("Word.Application")
X.Visible = False
X.Documents.Add
X.Selection.Text = "This is only a test"
X.ChangeFileOpenDirectory "C:\Test\"
X.ActiveDocument.SaveAs FileName:="Testing.htm", FileFormat:=wdFormatHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
X.ActiveDocument.Close savechanges:=wdDoNotSaveChanges
X.Quit
Set X = Nothing
-
..strange
I'm using Word97, so that the 8.0 Object Library. Version 9.0 is from Word2000 is it not? I still think it's strange, because in Word97 the Save as HTML functionality works, but it's not in the 8.0 object library. Any1 know a solution?
BTW, don't give me any SendKeys solutions. I'll only use them as a last resort!
Rick
-
Well does Word '97 have a Macro Recorder?
-
-
YES
Thanx man. I don't know why I didn't just try the macro recorder sooner. I use it in Excel all the time if I want to know the VBA code. Well, I have to use FileFormat:=102 and know it works!
Great!
-
No Problem, but if you are planning to use this on another PC you should maybe use
Code:
Sub SaveAsHTML()
Dim fcCnv As FileConverter
Dim strClass As String
Dim strFileName As String
' If there are no documents open to
' save, exit this routine.
If Documents.Count = 0 Then Exit Sub
' Set the ClassName to use for saving.
strClass = "HTML"
' Set the FileName to use for saving.
strFileName = "MyHTMLdoc"
' Loop through all installed converters.
For Each fcCnv In FileConverters
With fcCnv
' Test for conversion ClassName.
If .ClassName = strClass Then
' Save using the FileConverters.ClassName.
ActiveDocument.SaveAs FileName:=strFileName, _
FileFormat:=.SaveFormat
End If
End With
Next fcCnv
End Sub
I know that this seems ridiculously circuitous but check out the link in my last post for an explanation!
Good Luck