Hi all,
The following subs opens several files in one folder
(File Storage) and then saves the files to another
folder called 'BackUp' under different names.
The sub OpenDaFiles() works fine by itself,
but I get an "invalid procedure call or argument"
on *GetFile = Dir* when attempting to call
the sub SaveAsBackUp()
I don't know exactly what the cause is, but I
suspect that it's because the sub being called
also uses the Dir Function.
I've tried reffering back to the returned value
of the Dir Function *GetFile = Dir(MyPath)* in the
sub OpenDaFiles, but it doesn't work as it doesn't
loop properly.
Is there a way to programmatically get around this?
Any alternatives? I'm using WORD 97.
Sample code below.
Thanks. Peace!
Sub OpenDaFiles()
'
Dim MyPath, GetFile
ChangeFileOpenDirectory "C:\My Documents\File Storage\"
MyPath = "C:\My Documents\File Storage\"
GetFile = Dir(MyPath)
Do While GetFile <> ""
Documents.Open FileName:=GetFile, Format:=wdOpenFormatAuto
Call SaveAsBackUp ' possible error here!
GetFile = Dir ' possible error here!
Loop
End Sub
Public Sub SaveAsBackUp()
ChangeFileOpenDirectory "C:\My Documents\BackUp\"
Dim DestinationPath, DestPathFile
DestinationPath = "C:\My Documents\BackUp\"
' --> possible cause of error here? <--
DestPathFile = Dir(DestinationPath & MyFile)
If DestPathFile <> "" Then
msg = "File " & MyFile & " already exists in " & DestinationPath
msg = msg & vbCrLf & vbCrLf & " Overwrite?"
PromptMe = MsgBox(msg, vbExclamation + vbYesNo, "Save As"
End If
If PromptMe = vbNo Then
Exit Sub
Else
ActiveDocument.SaveAs FileName:=Whatever, FileFormat:= _
wdFormatText
End If
ActiveDocument.Close
End Sub
The following subs opens several files in one folder
(File Storage) and then saves the files to another
folder called 'BackUp' under different names.
The sub OpenDaFiles() works fine by itself,
but I get an "invalid procedure call or argument"
on *GetFile = Dir* when attempting to call
the sub SaveAsBackUp()
I don't know exactly what the cause is, but I
suspect that it's because the sub being called
also uses the Dir Function.
I've tried reffering back to the returned value
of the Dir Function *GetFile = Dir(MyPath)* in the
sub OpenDaFiles, but it doesn't work as it doesn't
loop properly.
Is there a way to programmatically get around this?
Any alternatives? I'm using WORD 97.
Sample code below.
Thanks. Peace!
Sub OpenDaFiles()
'
Dim MyPath, GetFile
ChangeFileOpenDirectory "C:\My Documents\File Storage\"
MyPath = "C:\My Documents\File Storage\"
GetFile = Dir(MyPath)
Do While GetFile <> ""
Documents.Open FileName:=GetFile, Format:=wdOpenFormatAuto
Call SaveAsBackUp ' possible error here!
GetFile = Dir ' possible error here!
Loop
End Sub
Public Sub SaveAsBackUp()
ChangeFileOpenDirectory "C:\My Documents\BackUp\"
Dim DestinationPath, DestPathFile
DestinationPath = "C:\My Documents\BackUp\"
' --> possible cause of error here? <--
DestPathFile = Dir(DestinationPath & MyFile)
If DestPathFile <> "" Then
msg = "File " & MyFile & " already exists in " & DestinationPath
msg = msg & vbCrLf & vbCrLf & " Overwrite?"
PromptMe = MsgBox(msg, vbExclamation + vbYesNo, "Save As"
End If
If PromptMe = vbNo Then
Exit Sub
Else
ActiveDocument.SaveAs FileName:=Whatever, FileFormat:= _
wdFormatText
End If
ActiveDocument.Close
End Sub