Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word 2 HTML (Word 2003)

    Hi, does anyone know of program that will convert a word document to HTML and create linked pages for every page of the word document rather than one continuous web page?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word 2 HTML (Word 2003)

    The following macro is based on MSKB article How to programmatically save each page or section of a document as a separate file. It will save each page of the active document in a separate HTML file.

    Notes:
    1) In this simple version, the path for the HTML files is specified at the beginning of the macro, and the files are named Page1.htm. Page2.htm etc. You can add bells and whistles as desired.
    2) The macro should not be stored in the document you want to split; a module in Normal.dot would be a good place for it.
    3) The document that has been split will be closed without saving at the end of the macro. Make sure that you have saved the document if necessary before running the macro.

    Sub Break2HTML()
    ' Path including trailing backslash
    Const strPath = "C:WebPages"
    Dim docC As Document
    Dim docN As Document
    Dim i As Integer
    Selection.HomeKey Unit:=wdStory
    Set docC = ActiveDocument
    ' Used to set criteria for moving through the document by page.
    Application.Browser.Target = wdBrowsePage
    For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
    ' Select and copy the text to the clipboard.
    docC.Bookmarks("page").Range.Copy
    ' Open new document to paste the content of the clipboard into.
    Set docN = Documents.Add
    Selection.Paste
    ' Removes the break that is copied at the end of the page, if any.
    Selection.TypeBackspace
    docN.SaveAs FileName:="Page" & i & ".htm", FileFormat:=wdFormatHTML, _
    AddToRecentFiles:=False
    docN.Close SaveChanges:=wdDoNotSaveChanges
    ' Move the selection to the next page in the document.
    Application.Browser.Next
    Next i
    docC.Close SaveChanges:=wdDoNotSaveChanges
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2 HTML (Word 2003)

    Can the code be modified to not change section numbering when pages are created. Also can you set the macro to work with section rather than pages?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word 2 HTML (Word 2003)

    I don't understand your first question. The original document isn't changed in any way, and HTML documents don't have sections. Can you explain what you mean?

    Here is a macro (based on the same Microsoft article) that splits a document by section instead of by page:

    Sub BreakSections2HTML()
    ' Path including trailing backslash
    Const strPath = "C:WebPages"
    Dim docC As Document
    Dim docN As Document
    Dim i As Integer
    Selection.HomeKey Unit:=wdStory
    Set docC = ActiveDocument
    ' Used to set criteria for moving through the document by section.
    Application.Browser.Target = wdBrowseSection
    For i = 1 To ActiveDocument.Sections.Count
    ' Select and copy the text to the clipboard.
    docC.Bookmarks("section").Range.Copy
    ' Open new document to paste the content of the clipboard into.
    Set docN = Documents.Add
    Selection.Paste
    ' Removes the break that is copied at the end of the page, if any.
    Selection.TypeBackspace
    docN.SaveAs FileName:="Section" & i & ".htm", FileFormat:=wdFormatHTML, _
    AddToRecentFiles:=False
    docN.Close SaveChanges:=wdDoNotSaveChanges
    ' Move the selection to the next page in the document.
    Application.Browser.Next
    Next i
    docC.Close SaveChanges:=wdDoNotSaveChanges
    End Sub

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2 HTML (Word 2003)

    The document has auto numbering turned on. When a new section heading is added all the sections are renumbered and the TOC is updated. When the original macro ran, the html pages it created all had section headings of 1.1.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word 2 HTML (Word 2003)

    Assuming that each section begins with a Heading 1 paragraph, you can use

    Sub BreakSections2HTML()
    ' Path including trailing backslash
    Const strPath = "C:WebPages"
    Dim docC As Document
    Dim docN As Document
    Dim i As Integer
    Selection.HomeKey Unit:=wdStory
    Set docC = ActiveDocument
    ' Used to set criteria for moving through the document by section.
    Application.Browser.Target = wdBrowseSection
    For i = 1 To ActiveDocument.Sections.Count
    ' Select and copy the text to the clipboard.
    docC.Bookmarks("section").Range.Copy
    ' Open new document to paste the content of the clipboard into.
    Set docN = Documents.Add
    Selection.Paste
    ' Removes the break that is copied at the end of the page, if any.
    Selection.TypeBackspace
    Selection.HomeKey Unit:=wdStory
    Selection.Range.ListFormat.ListTemplate.ListLevels (1).StartAt = i
    docN.SaveAs FileName:="Section" & i & ".htm", FileFormat:=wdFormatHTML, _
    AddToRecentFiles:=False
    docN.Close SaveChanges:=wdDoNotSaveChanges
    ' Move the selection to the next page in the document.
    Application.Browser.Next
    Next i
    docC.Close SaveChanges:=wdDoNotSaveChanges
    End Sub

    Otherwise it becomes rather complicated.

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2 HTML (Word 2003)

    thanks, i'll give this a try

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •