"Save as" for multiple documents

  • Thread starter Thread starter daves
  • Start date Start date
D

daves

Hi

Is there a way to automatically do a "save as" to multiple documents, found
in a single folder, while being able to specify the "Save as type"? For
example, I may one time need to save them as *.txt, other time as *.dot,...
anything that goes under the "save as type" list.

Thanks
 
Modify the code in the article "Find & ReplaceAll on a batch of documents in
the same folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

by deleting all the Find and Replace stuff and just changing the way that
the file is saved.
--
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
 
vba.beginners or any of the vba newsgroups would be better.

--
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
 
The following will allow you to save a folder of Word documents in a number
of common formats. The numbers are those associated with the particular file
types and not an indication that I cannot count ;)


Sub SaveAllAsType()
Dim strFileName As String
Dim strDocName As String
Dim strPath As String
Dim oDoc As Document
Dim Response As Long
Dim fDialog As FileDialog
Dim sTypeNo As Integer
Dim sExt As String

sTypeNo = InputBox("Save documents in which format?" & vbCr & _
" 0 = Microsoft Office Word format." & vbCr & _
" 2 = Microsoft Windows text format." & vbCr & _
" 4 = Microsoft DOS text format." & vbCr & _
" 5 = Microsoft DOS text with line breaks preserved." & vbCr & _
" 6 = Rich text format (RTF)." & vbCr & _
" 8 = Standard HTML format." & vbCr & _
"10 = Filtered HTML format." & vbCr & vbCr & _
"Enter the number associated with the file type", "File Type",
2)

Select Case sTypeNo
Case Is = "0"
sExt = ".doc"
Case Is = "2"
sExt = ".txt"
Case Is = "4"
sExt = ".txt"
Case Is = "5"
sExt = ".txt"
Case Is = "6"
sExt = ".rtf"
Case Is = "8"
sExt = ".html"
Case Is = "10"
sExt = ".html"
Case Else
MsgBox "Incorrect number selected", vbExclamation
Exit Sub
End Select

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", , "Save all"
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

strFileName = Dir$(strPath & "*.doc")

While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)

strDocName = ActiveDocument.FullName
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & sExt
oDoc.SaveAs FileName:=strDocName, _
FileFormat:=sTypeNo
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFileName = Dir$()
Wend
End Sub

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


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
The nice thing about this code is that with slight changes one can add other
formats included in the Word SaveAs list. Also, one can make a conversion
back to .doc with the correct modification of the code. 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

Back
Top