How do I output Word 2003 merge as HTML?

M

M.L.

Hi. I'm just learning how to use Word 2003 mail merge to create
HTML templates for my website. The only problem is that the
resulting pages are output as .doc files instead of .html. Is there
a way I can set mail merge options to output my result as HTML
files instead? Thanks.
 
G

Graham Mayor

Look at the variety of file types you can save a document as from the File >
Save As dialog!

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

M.L.

Hi. I'm just learning how to use Word 2003 mail merge to create
Look at the variety of file types you can save a document as from the
File > Save As dialog!

Thanks for your reply. However, the Word 2000 mailmerge does not
offer a Save As dialog box when it gets ready to merge the document.
The results are automatically saved as .doc files.
 
G

Graham Mayor

Oops - sorry, I hadn't had my breakfast when I wrote that. I was forgetting
which group I was in.

You could output to a new document and use the splitter macro from
http://www.gmayor.com/individual_merge_letters.htm to break to individual
documents saved as html.

Change the fileformat in the line
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
to
wdFormatHTML
and the extension in the line
DocName = "D:\My Documents\Temp\Workgroup\" & Format(Date, mask) _
& " " & LTrim$(Str$(Counter)) & ".doc"
from doc to htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

M.L.

Hi. I'm just learning how to use Word 2003 mail merge to create
Oops - sorry, I hadn't had my breakfast when I wrote that. I was
forgetting which group I was in.

You could output to a new document and use the splitter macro from
http://www.gmayor.com/individual_merge_letters.htm to break to
individual documents saved as html.

Change the fileformat in the line
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
to
wdFormatHTML
and the extension in the line
DocName = "D:\My Documents\Temp\Workgroup\" & Format(Date, mask) _
& " " & LTrim$(Str$(Counter)) & ".doc"
from doc to htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

I don't know much about scripting and expected something
simpler. But if I have to I'll give it a try. Thanks again.
 
M

M.L.

Hi. I'm just learning how to use Word 2003 mail merge to create
I don't know much about scripting and expected something
simpler. But if I have to I'll give it a try. Thanks again.

While trying to solve my mailmerge conversion issue I Googled upon
a May 7, 2004 post of yours which explained this issue in more detail.
Specifically, you wrote the following macro to convert doc files to HTML:
*******************************
Public Sub BatchSaveAsHTML()
Dim myFile As String
Dim myHTML As String
Dim myLen As String
Dim myLen2 As String
Dim PathToUse As String
Dim myDoc As Document

With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With

If Documents.Count > 0 Then
Documents.Close Savechanges:=wdPromptToSaveChanges
End If

If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If

myFile = Dir$(PathToUse & "*.doc")

While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
myLen = Len(myFile)
myLen2 = myLen - 3
myHTML = Left(myFile, myLen2) & "HTML"
myDoc.SaveAs FileName:=myHTML, FileFormat:=wdFormatHTML
myDoc.Close Savechanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub
*********************************************

I notice that your reply contains some slight changes from the earlier
version.
I installed your macro and it worked well, and was faster than I thought
it would be. However, I do have some questions:

1.) The output HTML files were saved to the "my documents folder." Is there
a way I can set the output files to the folder of my choice? Or could I at
least set the
output to be saved in the same folder from which I loaded my original doc
files?

2.) The HTML is not filtered and therefore I get some extra data in the HTML
source. Is there a way I can clean up the HTML during the macro?

3.) Does it matter that the Word default macro template does not contain
the word "Public" preceeding the word sub?

In addition, when I went to your website I downloaded the macro that splits
the
merged file into separate files (MMtoDocsRev19.dot). Your tutorial on that
macro
showed some familiar screenshots. I realized that your macro was already on
my
Word 2003 system, even though I don't remember ever having placed it there.
It is located in my Applications Data\Microsoft\Word startup folder
as MailMergetoDocsRev19.dot. Are the two files equivalent?

I'd like to again thank you so much for all your assistance in this matter.
 
P

Peter Jamieson

Graham's website suggests he's out of the picture for a few weeks, so I'll
answer what I can...
1.) The output HTML files were saved to the "my documents folder." Is
there
a way I can set the output files to the folder of my choice? Or could I at
least set the
output to be saved in the same folder from which I loaded my original doc
files?

The values returned by "Dir()" are just the file names, not the full path
names, so in this case you could you could change

myHTML = Left(myFile, myLen2) & "HTML"

to

myHTML = PathToUse & Left(myFile, myLen2) & "HTML"

(It seems that Graham is already assuming that PathToUse is empty or ends
with a "\" or just contains said:
2.) The HTML is not filtered and therefore I get some extra data in the
HTML
source. Is there a way I can clean up the HTML during the macro?

Try changing

myDoc.SaveAs FileName:=myHTML, FileFormat:=wdFormatHTML

to

myDoc.SaveAs FileName:=myHTML, FileFormat:=wdFormatFilteredHTML
3.) Does it matter that the Word default macro template does not contain
the word "Public" preceeding the word sub?

Not really, when you're just running the macro as a one-off in this way.
When you're writing a suite of macros, getting declarations such as this one
"correct" becomes more important if not critical. But you'ld be better off
asking in a general VBA programming group about that.
It is located in my Applications Data\Microsoft\Word startup folder
as MailMergetoDocsRev19.dot. Are the two files equivalent?

Don't know, sorry. Doug Robbins may be able to tell you if you post another
message (don't use the same title) just describing this one issue.

Peter Jamieson
 
M

M.L.

Peter Jamieson said:
Graham's website suggests he's out of the picture for a few weeks, so I'll
answer what I can...


The values returned by "Dir()" are just the file names, not the full path
names, so in this case you could you could change

myHTML = Left(myFile, myLen2) & "HTML"

to

myHTML = PathToUse & Left(myFile, myLen2) & "HTML"

(It seems that Graham is already assuming that PathToUse is empty or ends


Try changing

myDoc.SaveAs FileName:=myHTML, FileFormat:=wdFormatHTML

to

myDoc.SaveAs FileName:=myHTML, FileFormat:=wdFormatFilteredHTML


Not really, when you're just running the macro as a one-off in this way.
When you're writing a suite of macros, getting declarations such as this
one "correct" becomes more important if not critical. But you'd be better
off asking in a general VBA programming group about that.


Don't know, sorry. Doug Robbins may be able to tell you if you post
another message (don't use the same title) just describing this one issue.

Peter Jamieson

Thanks Peter, I'll incorporate the changes into the macro. BTW, I found that
Word has an option that allows me to save *all* files as filtered HTML. I
could just set that option on or off when needed.
 

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