Results 1 to 9 of 9

Thread: Word to HTML conversion

  1. #1

    Thread Starter
    Addicted Member reznor's Avatar
    Join Date
    May 2001
    Location
    Netherlands
    Posts
    151

    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

  2. #2
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    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

  3. #3

    Thread Starter
    Addicted Member reznor's Avatar
    Join Date
    May 2001
    Location
    Netherlands
    Posts
    151

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

  4. #4
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    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

  5. #5

    Thread Starter
    Addicted Member reznor's Avatar
    Join Date
    May 2001
    Location
    Netherlands
    Posts
    151

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

  6. #6
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    Well does Word '97 have a Macro Recorder?

  7. #7
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671

  8. #8

    Thread Starter
    Addicted Member reznor's Avatar
    Join Date
    May 2001
    Location
    Netherlands
    Posts
    151

    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

  9. #9
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    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
  •  



Click Here to Expand Forum to Full Width