Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Save As .htm

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve C - 17 Apr 2007 19:02 GMT
After merging 125 employee records into a one-page mail merge document, I
have the expected document (Results.doc) with 125 individual pages as a
result.  I wish to save each page of this document as an individual .htm
file, using the first line of each page (the employee's name) as the file
name.  I wish to save them to G:\Sample.  The end result I'm looking for is
125 individual .htm files.

Is there a way to do this programmatically?  Thanks in advance for any help
or ideas you can give me!
Signature

Steve C

Brian - 18 Apr 2007 09:38 GMT
If you make each name a header,using the same format, try the following,
changing the base folder to where you want the output:

Sub xSplitter()

Dim DocumentData As String

Selection.WholeStory
Selection.Copy

BaseFolder = "D:\Output\"
BaseName = "Let"
Application.DefaultSaveFormat = "html"

Documents.Add
Selection.Paste

DocName = BaseFolder & BaseName
ActiveDocument.SaveAs FileName:=DocName
ActiveWindow.Close

Close

Open BaseFolder & BaseName & ".htm" For Input As #1

DocumentData = Input(LOF(1), #1)

Close

pos = InStr(DocumentData, "</head>")

DocumentHeader = Mid(DocumentData, 1, pos + Len("</head>"))

pos = InStr(DocumentData, "<body")

Counter = 1

While pos <> 0
   
   StartOfHeader = InStr(pos, DocumentData, "<h1>")
   endOfheader = InStr(pos, DocumentData, "</h1>")
   StartOfNextHeader = InStr(StartOfHeader + 1, DocumentData, "<h1>")
   
   HeaderTitle = Filter((Mid(DocumentData, StartOfHeader, endOfheader -
StartOfHeader)))
   
   Open BaseFolder & BaseName & Right$("000" & LTrim$(Str$(Counter)), 3) &
"-" & HeaderTitle & ".htm" For Output As #1
       
   Counter = Counter + 1
   
   Print #1, DocumentHeader
   Print #1, "<body>"
   If StartOfNextHeader > 0 Then
     Print #1, Mid(DocumentData, StartOfHeader, StartOfNextHeader -
StartOfHeader)
   Else
     Print #1, Mid(DocumentData, StartOfHeader)
   End If
   
   Print #1, "</body>"
   Print #1, "</html>"
   
   Close
         
   pos = StartOfNextHeader
   
Wend

Close

End Sub

Hope it helps,

Signature

Brian McCaffery

> After merging 125 employee records into a one-page mail merge document, I
> have the expected document (Results.doc) with 125 individual pages as a
[quoted text clipped - 5 lines]
> Is there a way to do this programmatically?  Thanks in advance for any help
> or ideas you can give me!
Steve C - 18 Apr 2007 14:26 GMT
Brian,

Thanks.  I really appreciate the time and effort to help me.  I've made each
name a header as you suggested, using <h1>EmployeeName</h1>, but I'm getting
a compile error "Argument not optional" on the following line:

HeaderTitle = Filter((Mid(DocumentData, StartOfHeader, endOfheader -
StartOfHeader)))

Thoughts?
Signature

Steve C

> If you make each name a header,using the same format, try the following,
> changing the base folder to where you want the output:
[quoted text clipped - 80 lines]
> > Is there a way to do this programmatically?  Thanks in advance for any help
> > or ideas you can give me!
Brian - 19 Apr 2007 09:56 GMT
That was code amended by another poster. So will have to check. The code I
initially sent is below, If you split the document into sections and run the
code, it should create individual html files calling each, LET1, LET2, etc. I
will try to amend the code to pick up the header for the file name.

Sub Splitter()
Selection.EndKey Unit:=wdStory
numlets = Selection.Information(wdActiveEndSectionNumber)
If numlets > 1 Then numlets = numlets - 1
Selection.HomeKey Unit:=wdStory
BaseName = "c:\Let"
Application.DefaultSaveFormat = "html"
For Counter = 1 To numlets
DocName = BaseName & Right$("000" & LTrim$(Str$(Counter)), 3)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=DocName
ActiveWindow.Close
Next Counter
End Sub

hope this is a step forward.

Signature

Brian McCaffery

> Brian,
>
[quoted text clipped - 91 lines]
> > > Is there a way to do this programmatically?  Thanks in advance for any help
> > > or ideas you can give me!
Brian - 18 Apr 2007 11:12 GMT
PS,

Don't forget to backup.
Signature

Brian McCaffery

> After merging 125 employee records into a one-page mail merge document, I
> have the expected document (Results.doc) with 125 individual pages as a
[quoted text clipped - 5 lines]
> Is there a way to do this programmatically?  Thanks in advance for any help
> or ideas you can give me!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.