Question about ActiveWorkbook.SaveAs()
Hi Robert,
Am Thu, 24 Dec 2015 01:44:18 -0700 schrieb Robert Crandal:
Is there a way to determine whether the user selected
"Yes" or "No" to replace the file?
you could determine to replace always with
Application.DisplayAlerts=False
e.g.:
Dim j As Integer
Const mypath = "C:\data\"
Application.DisplayAlerts = False
For j = 1 To 3
ActiveWorkbook.SaveAs Filename:=mypath & "myfile" & j & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
Next ' j
Application.DisplayAlerts = True
You also could create an addition to the name if the direction exists:
Dim j As Integer
Dim extra As String
Const mypath = "C:\data\"
For j = 1 To 3
extra = IIf(Dir(mypath & "myfile" & j & ".xlsm") < "", "New", "")
ActiveWorkbook.SaveAs Filename:=mypath & "myfile" & j & extra &
".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
Next ' j
If the saving is already done you could open the file and check the
creation data. if it is older as expected the user selected "no":
Dim j As Integer
Const mypath = "C:\data\"
Workbooks.Open mypath & "myfile1.xlsm"
MsgBox "Creation Date: " & ActiveWorkbook.BuiltinDocumentProperties(11)
Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
|