PDA

View Full Version : Save open document to another directory



presence76
03-01-2006, 04:53 PM
I am running through a directory and determining if a document has one or two pages, then saving that document to an appropriately named folder. I have the new folders created but when I have the document open, I cannot figure out how to tell VBA to save this document to the right folder. I have tried the following code:



Sub checkpages()

Dim fso As FileSystemObject
Dim fldr As Folder
Dim f As File
Dim myDoc As Document
Dim totpages As Integer
Dim onepagedir As String
Dim twopagedir As String

onepagedir = "P:\Clients\Vanguard\Finance\testing\onepagedocs\"
twopagedir = "P:\Clients\Vanguard\Finance\testing\twopagedocs\"

If Dir(onepagedir) <> "" Then Kill onepagedir

If Dir(twopagedir) <> "" Then Kill twopagedir

MkDir (onepagedir)
MkDir (twopagedir)


Const TARGET_FOLDER As String = "P:\Clients\Vanguard\Finance\testing\"

Set fso = New FileSystemObject
Set fldr = fso.GetFolder(TARGET_FOLDER)
For Each f In fldr.Files
If Right(f.Name, 4) = ".doc" Then
Set myDoc = Documents.Open(TARGET_FOLDER & f.Name)
totpages = Selection.Information(wdNumberOfPagesInDocument)
If totpages = 1 Then
myDoc.Copy (onepagedir)
' myDoc.PrintOut
myDoc.Close False
Else
myDoc.Close False
End If
End If
Next f

End Sub



VBA does not like the "mydoc.Copy (onepagedir) statement.

I tried looking around this site for similar situations but could not find one.

Thanks in advance.

presence76
03-01-2006, 05:38 PM
I found a solution

On the Mydoc.copy (onepagedir) line

I changed it to:

myDoc.SaveAs FileName:=onepagedir & f.Name

Thanks.

mdmackillop
03-01-2006, 05:39 PM
f.Copy onepagedir