|
-
Aug 3rd, 2001, 03:00 AM
#1
Thread Starter
Addicted Member
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 , 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
"Computers are incredibly fast, accurate and stupid. Human beings are incredibly slow, inaccurate and brilliant. Together they are powerful beyond imagination." - Albert Einstein
-
Aug 3rd, 2001, 03:12 AM
#2
Fanatic Member
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
-
Aug 3rd, 2001, 03:27 AM
#3
Thread Starter
Addicted Member
..nope
thanx for your reply, but...
This doesn't work from VB. It gives me a variable not defined error on wdFormatHTML.
Any1 else???
"Computers are incredibly fast, accurate and stupid. Human beings are incredibly slow, inaccurate and brilliant. Together they are powerful beyond imagination." - Albert Einstein
-
Aug 3rd, 2001, 03:41 AM
#4
Fanatic Member
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
-
Aug 3rd, 2001, 03:45 AM
#5
Thread Starter
Addicted Member
..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
"Computers are incredibly fast, accurate and stupid. Human beings are incredibly slow, inaccurate and brilliant. Together they are powerful beyond imagination." - Albert Einstein
-
Aug 3rd, 2001, 04:32 AM
#6
Fanatic Member
Well does Word '97 have a Macro Recorder?
-
Aug 3rd, 2001, 04:36 AM
#7
Fanatic Member
-
Aug 3rd, 2001, 04:51 AM
#8
Thread Starter
Addicted Member
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!
"Computers are incredibly fast, accurate and stupid. Human beings are incredibly slow, inaccurate and brilliant. Together they are powerful beyond imagination." - Albert Einstein
-
Aug 3rd, 2001, 05:00 AM
#9
Fanatic Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|