Save As Automation

K

Kev

Hi there

I am converting a large amount of pdf documents into Word format. The
program I am using will perform multiple conversions at once when
opening the PDFs into word (PDF Convertor 3)
Unfortunately it wont bulk save them.
At the end of opening all thedocuments, I am left with multiple
documents open in word. If I click on "SAVE AS" it opens a dialog box
with the suggested file name filled in. This name is created form the
source PDF.

I want to create a macro that will save the file using the suggested
name, then close it.

I have created one, but they all keep saving as the same file name
(Resume1.doc).

How do I code the variable please so that when I run the macro, the
file saves with it's suggested name?

--------------------------------------------------------------------------------------------------------
ActiveDocument.SaveAs FileName:="resume1.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveDocument.Close
---------------------------------------------------------------------------------------
 
J

Jonathan West

Hi Kev

I suspect that the PDF converter has put the suggested filename into the
Title property of the file. If so, then the way to fix your code is as
follows

Dim sTitle as String
sTitle = ActiveDocument.BuiltInDocumentProperties("Title") & ".doc"
ActiveDocument.SaveAs FileName:=sTitle
ActiveDocument.Close


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
W

Word Heretic

G'day "Kev" <[email protected]>,

Const myPrefix as String = "Resume"
Dim OpenDoc as Document
Dim MyNum as Long

MyNum = 1

for each OpenDoc in Documents
with opendoc
.SaveAs myPrefix & format$(mynum)
.close
mynum=mynum+1
end with
next

set opendoc = nothing

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Kev reckoned:
 
K

Kev

Thanks guys, cant wait to try it out. 1 further question if I may? If
I have say 15 documents open, how could I adjust the macro to close ALL
open documents, and perform the same SAVE AS function? I'd like to hit
1 key and have them all close and save at once.

Cheers

Kevin
 
J

Jezebel

Dim pDoc as word.document
For each pDoc in Documents
pDoc.SaveAs ....
pDoc.Close
Next
 
K

Kev

Thanks heaps Jezebel.
Can I ask, how would I go about using word to do this for all documents
in a specific folder?

The PDF convertor app allows the opening of PDF documents in Word.
What I'm wondering is, can I open word, then run a macro that would
open all documents in a specified folder, and do the save as process as
we've discussed?

I'm trying to automate this conversion process as much as possible, as
there are approx 2000 documents to convert.

Thanks so much for all your help.
Kev
 
K

Kev

Here is my final code. I put together from other posts plus my own
input.
This script opens each file 1 at a time, executes a macro, then closes
the document.

Sub MacroRunnerWithArrays()

Dim FolderPath As String
Dim macroName As String
Dim oDoc As Document

Application.ScreenUpdating = False
FolderPath = "S:\public\Testing - Emerge\Unprocessed"
macroName = "Macro1"

With Application.FileSearch
.NewSearch
.LookIn = FolderPath
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If Not .Execute() = 0 Then
For j = 1 To .FoundFiles.Count
Set oDoc = Documents.Open(.FoundFiles(j))
Application.Run macroName
ActiveDocument.Close
Set oDoc = Nothing
Next j
Else
MsgBox "No files in specified folder(s)"
End If
End With
Application.ScreenUpdating = True
MsgBox "All Done"
End Sub

***** Here is the code for Macro 1 which Performs the Save As function
*****

Sub Macro1()
'
Dim pDoc As Word.Document
docpath = "S:\public\Testing - Emerge\Processed\"

For Each pDoc In Documents
sTitle = ActiveDocument.Name
pos = InStr(sTitle, ".")
If pos > 0 Then
sTitle = Left(sTitle, pos - 1)
sTitle = docpath & sTitle & ".doc"
ActiveDocument.SaveAs FileName:=sTitle
'ActiveDocument.Close
End If
Next
End Sub

*** Note I commented out the document close on Macro1 as it was already
coded in the first Macro ***
 

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