A
arne
This routine saves a large doc as htm page by page, inserting hyperlinks to
next page, first page and startpage.
All htm files are saved in the same folder, and eveyrthing works OK except
links on the first page and the last page and table of contents..
Need help and input1. The solution of savng everything in one htm file
works, but that htm file is to large since it contains a lot of pictures
etc..
Several problems here to solve.. please? Regards Arne
'
' Routine starts
Sub arnes_convert_doc_to_htm_page_by_page()
'Purpose: save documents to htm page by page with next back and home
hyperlinks into a created folder
' here it is "e:\docweb\" Change it for yor needs
' Problem 1: inserting correct hyperlinks on first and last page when I save
word doc as htm
' Problem 2: Table of contents (hyperlinks) does not link to correct page
' Problem 3: Empty clipboard
' tested on on word 200
' code mixed and done by Arne, with the help from my books, newsgroups and a
demand from my boss
' can be modified to save each section, a better solution for most documents
saved as htm
' starts this with the doc YOU want to convert and create and change
DIRECTORY e:\docweb\ for your needs
' Your DOC must contain text... This ONE does not check for that
' place this in normal dot or elsewhere...
'removes file extension and trims the filename
' working code below with the limits mentioned in Problems
Dim oridocname As String ' my active document I want to convert
oridocname = ActiveDocument.Name
oridocname = Trim(Left(oridocname, Len(oridocname) - 4)) '
Dim docname
' SAVES the pages one after another
' If the same doc has done the same procedure the other docs will be
overwritting!!
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
' ADDS hyperlinks to each page on the "bottom"
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range,
Address:=Docnum & "Page_" & oridocname & ".htm", _
ScreenTip:="Back", TextToDisplay:=" [ BACK ] "
''''' PROBLEM THE FIRST PAGE HAS NOTHING TO GO BACK TO
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=Docnum + 2 &
"Page_" & oridocname & ".htm", _
ScreenTip:="Next??", TextToDisplay:=" [ Next ] "
'''' Problem!! The last saved htm page refers to the next page which does
not exist, how to solve that??
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=1 &
"Page_" & oridocname & ".htm", _
ScreenTip:="Home??", TextToDisplay:=" [ 1.PAGE ] "
''''' The first page can not go home
' this directory is created before I start this
ChangeFileOpenDirectory "e:\docweb\"
' increments the document number and give each page a name based on their
pagenumber
Docnum = Docnum + 1
' saves the current page as htm
ActiveDocument.SaveAs FileName:=Docnum & "Page_" & oridocname & ".htm",
FileFormat:= _
wdFormatHTML, LockComments:=False, Password:="",
AddToRecentFiles:=False, _
WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:=False
ActiveDocument.Close
' need a routine to clear Office clipboard here!! VBS script???
Application.Browser.Next
Next i
' go to the beginning of the orignal document
Selection.HomeKey Unit:=wdStory
MsgBox "Now the document " & oridocname & " " & " is exportet page by
page into htmformat!", vbInformation
End Sub
next page, first page and startpage.
All htm files are saved in the same folder, and eveyrthing works OK except
links on the first page and the last page and table of contents..
Need help and input1. The solution of savng everything in one htm file
works, but that htm file is to large since it contains a lot of pictures
etc..
Several problems here to solve.. please? Regards Arne
'
' Routine starts
Sub arnes_convert_doc_to_htm_page_by_page()
'Purpose: save documents to htm page by page with next back and home
hyperlinks into a created folder
' here it is "e:\docweb\" Change it for yor needs
' Problem 1: inserting correct hyperlinks on first and last page when I save
word doc as htm
' Problem 2: Table of contents (hyperlinks) does not link to correct page
' Problem 3: Empty clipboard
' tested on on word 200
' code mixed and done by Arne, with the help from my books, newsgroups and a
demand from my boss
' can be modified to save each section, a better solution for most documents
saved as htm
' starts this with the doc YOU want to convert and create and change
DIRECTORY e:\docweb\ for your needs
' Your DOC must contain text... This ONE does not check for that
' place this in normal dot or elsewhere...
'removes file extension and trims the filename
' working code below with the limits mentioned in Problems
Dim oridocname As String ' my active document I want to convert
oridocname = ActiveDocument.Name
oridocname = Trim(Left(oridocname, Len(oridocname) - 4)) '
Dim docname
' SAVES the pages one after another
' If the same doc has done the same procedure the other docs will be
overwritting!!
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
' ADDS hyperlinks to each page on the "bottom"
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range,
Address:=Docnum & "Page_" & oridocname & ".htm", _
ScreenTip:="Back", TextToDisplay:=" [ BACK ] "
''''' PROBLEM THE FIRST PAGE HAS NOTHING TO GO BACK TO
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=Docnum + 2 &
"Page_" & oridocname & ".htm", _
ScreenTip:="Next??", TextToDisplay:=" [ Next ] "
'''' Problem!! The last saved htm page refers to the next page which does
not exist, how to solve that??
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=1 &
"Page_" & oridocname & ".htm", _
ScreenTip:="Home??", TextToDisplay:=" [ 1.PAGE ] "
''''' The first page can not go home
' this directory is created before I start this
ChangeFileOpenDirectory "e:\docweb\"
' increments the document number and give each page a name based on their
pagenumber
Docnum = Docnum + 1
' saves the current page as htm
ActiveDocument.SaveAs FileName:=Docnum & "Page_" & oridocname & ".htm",
FileFormat:= _
wdFormatHTML, LockComments:=False, Password:="",
AddToRecentFiles:=False, _
WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:=False
ActiveDocument.Close
' need a routine to clear Office clipboard here!! VBS script???
Application.Browser.Next
Next i
' go to the beginning of the orignal document
Selection.HomeKey Unit:=wdStory
MsgBox "Now the document " & oridocname & " " & " is exportet page by
page into htmformat!", vbInformation
End Sub