Save new document as MHT format

S

Stacey Bailey

Hi. I have a macro that I've used in the past to slice up Mailmerged
documents into separate files. In the past, I've exported the files as xml
using the text format and an xml extension.

I'm trying to repurpose that macro to generate .mht files (single file web
pages). I can generate the files as .htm using:
ActiveDocument.SaveAs FileName:=Title & ".htm", FileFormat:=wdFormatHTML

There doesn't seem to be a wdformat for .htm nor does there seem to be a
file converter available.

Has anyone done this? Any ideas on what to try?
 
Joined
Jan 7, 2023
Messages
1
Reaction score
0
Maybe you can try this VBA code

Sub Convert()

Dim filePath As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
filePath = .SelectedItems(1)
End With

If filePath = "" Then Exit Sub
If Right(filePath, 1) <> "\" Then filePath = filePath & "\"

Application.ScreenUpdating = False

Dim currFile As String
currFile = Dir(filePath & "*.docx")

Do While currFile <> ""

Documents.Open (filePath & currFile)
Documents(currFile).SaveAs2 FileName:=filePath & Left(currFile, Len(currFile) - Len(".docx")) & ".mht", FileFormat:=wdFormatWebArchive
Documents(currFile).Close

currFile = Dir()
Loop

currFile = Dir(filePath & "*.doc")

Do While currFile <> ""

Documents.Open (filePath & currFile)
Documents(currFile).SaveAs2 FileName:=filePath & Left(currFile, Len(currFile) - Len(".docx")) & ".mht", FileFormat:=wdFormatWebArchive
Documents(currFile).Close

currFile = Dir()
Loop

Application.ScreenUpdating = True

End Sub
 

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