Saving mht files as .doc or .rtf

P

Paul

I have a large collection of .mht files that I have decided to convert to MS
Word (.doc) files (Desktop search engines have too much touble indexing
their contents). I will be opening them up in MS Word whenever I want to
read one, but I'm wondering if I can get Word at all to save this in a .doc
or even .rtf file format--without my going to the file-save as menu?
 
G

Graham Mayor

Not really, but you can automate the process. The following macro will open
and save all the mht files in a folder as Word DOC into the same folder
(re-writing any existing document of the same name in that folder without
prompting - so move them to a safe location before running the macro). The
macro also assumes that you have used a standard naming convention i.e.
without extra full stops (periods) .

http://www.gmayor.com/installing_macro.htm

Sub SaveMHTAsDoc()
Dim fName() As String
Dim strFile As String
Dim strPath As String
Dim strDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.mht")
While strFile <> ""
Set strDoc = Documents.Open(strPath & strFile)
fName = Split(strDoc, ".")
ActiveWindow.View.Type = wdPrintView
With strDoc
.SaveAs FileName:=fName(0) & ".doc", _
FileFormat:=wdFormatDocument
.Close
End With
strFile = Dir$()
Wend
End Sub

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Paul

Graham, that was a big big help. OK if I don't get anything more that will
be a huge time saver. I have tons of files that I've saved over the years as
mht and this definitely makes it quicker, as I just can't expect these
desktop search engines to all index them.

I now have another question. WHen I used it in one folder (My
Documents/Economics) it saved them with a pretty good fidelity, but in the
My Documents directory. Is there any tweak I can make that would send them
right back into teh sub-directory they were originally in (as mht)?
 
G

Graham Mayor

It should already save the documents in the same folder, however the
following mod should ensure that it does:

Sub SaveMHTAsDoc()
Dim fName() As String
Dim sOpt As Boolean
Dim strFile As String
Dim strPath As String
Dim strDoc As Document
Dim fDialog As FileDialog
sOpt = Options.ConfirmConversions
Options.ConfirmConversions = False
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.mht")
While strFile <> ""
Set strDoc = Documents.Open(strPath & strFile)
fName = Split(strFile, ".")
ActiveWindow.View.Type = wdPrintView
With strDoc
.SaveAs FileName:=strPath & fName(0) & ".doc", _
FileFormat:=wdFormatDocument
.Close
End With
strFile = Dir$()
Wend
Options.ConfirmConversions = sOpt
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Paul

Incredible Graham. THanks a lot.

I do have one more question. When Word is saving these files, 70% of teh
time I get, for each file, a popup window that says something like "Linked
style sheets are only supported in web format files. By saivng to this
format, all links to style sheets will be lost."

Is there any way I can disable this error notification?
 
G

Graham Mayor

I suspect not - I don't know of one.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Paul

That's alright that would have been just the frosting on the cake--the
lion's share of teh work has already been saved by your macro. Thanks again.
 

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