Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

Save As Automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kev - 06 Apr 2006 09:46 GMT
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
---------------------------------------------------------------------------------------
Jonathan West - 06 Apr 2006 10:55 GMT
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

Signature

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

> Hi there
>
[quoted text clipped - 26 lines]
>    ActiveDocument.Close
> ---------------------------------------------------------------------------------------
Kev - 07 Apr 2006 04:54 GMT
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
Jezebel - 07 Apr 2006 05:27 GMT
Dim pDoc as word.document
For each pDoc in Documents
   pDoc.SaveAs ....
   pDoc.Close
Next

> 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
[quoted text clipped - 4 lines]
>
> Kevin
Kev - 10 Apr 2006 00:44 GMT
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
Kev - 11 Apr 2006 05:07 GMT
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 ***
Word Heretic - 06 Apr 2006 11:06 GMT
G'day "Kev" <kblair@emerge.net.au>,

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:

>Hi there
>
[quoted text clipped - 26 lines]
>    ActiveDocument.Close
>---------------------------------------------------------------------------------------
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.