export to multiple html files

C

cc

Hi,

Is there anyway to export a word document into multiple html
documents. I'd like the output document to be cut at a certain heading
level. I.e each heading2 becomes the beginning of a new output file.

thanks,
 
D

Doug Robbins - Word MVP

The following code in a macro should do it:

Dim i As Long
Dim asection As Range
Dim newdoc As Document
With ActiveDocument
For i = .Paragraphs.Count To 1 Step -1
If .Paragraphs(i).Style = "Heading 2" Then
Set asection = .Paragraphs(i).Range
asection.End = .Range.End
Set newdoc = Documents.Add
newdoc.Range.FormattedText = asection.FormattedText
newdoc.SaveAs FileName:="Section" & i, FileFormat:=wdFormatHTML
newdoc.Close
asection.Delete
End If
Next
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top