普段使っているのはこれ...
Sub Sample()
Dim fullFileName
fullFileName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If fullFileName <> False Then
If fileExists(fullFileName) = False Then
ActiveWorkbook.SaveAs fullFileName
Else
MsgBox "File Exists. File Save Aborted"
End If
End If
End Sub
Public Function fileExists(strFullPath As Variant) As Boolean
On Error GoTo Whoa
If Not Dir(strFullPath, vbDirectory) = vbNullString Then fileExists = True
Whoa:
On Error GoTo 0
End Function
ファローアップ
こんな感じですか?
Sub Sample()
Dim fullFileName
Dim conti As Boolean
conti = True
Do While conti = True
fullFileName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If fullFileName <> False Then
If fileExists(fullFileName) = False Then
ActiveWorkbook.SaveAs fullFileName
conti = False
Else
MsgBox "File Exists. Returning you back to the dialog box"
End If
Else
conti = False
End If
Loop
End Sub
Public Function fileExists(strFullPath As Variant) As Boolean
On Error GoTo Whoa
If Not Dir(strFullPath, vbDirectory) = vbNullString Then fileExists = True
Whoa:
On Error GoTo 0
End Function