Justaguy,
Naast de "hoofdcode" heb je dan ook een functie nodig om te controleren of die file al bestaat of niet.
Dit kan o.a. zo:
Deze functie gebruik je om te zien of de file bestaat:
Function FileExists(FullFileName) As Boolean
' Checks if a certain file exists
FileExists = CBool(Dir(FullFileName) <> "")
End Function
Dit zou je "hoofdcode" ongeveer moeten zijn:
Sub SaveWithOptions()
Application.DisplayAlerts = False
target = "D:\!Docs\overwrite.xls"
If FileExists(target) Then
yourchoice = MsgBox("This file already exists!" & vbCrLf & vbCrLf & _
"Click:" & vbCrLf & _
"YES: to overwrite the file and close." & vbCrLf & _
"NO: to close without saving" & vbCrLf & _
"CANCEL: to leave the file open", vbYesNoCancel)
Select Case yourchoice
Case vbYes: ActiveWorkbook.SaveAs target
Case vbNo: ActiveWorkbook.Close savechanges = False
Case vbCancel: Exit Sub
End Select
Else
ActiveWorkbook.SaveAs target
End If
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Succes,
Bart
PS: In de file in bijlage moet je E:\!Docs\overwrite.xls naar je eigen filepath veranderen...