I have some code here that checks to see if a path exists, creates the path/dir if it doesn't exist, and then saves the active workbook in the dir. This works great, once. Problem comes in if the file already exists then Excel prompts the user asking if they want to overwrite. If the user says no, my VB errors out. Is there anyway to stop my VB from puking? Or my 2nd choice would be to stop excel from prompting and just automatically overwrite the file? Here is my current code:
Private Sub savebutton_Click()
Path = "c:worksheets"
If PathExists(Path) = False Then MkDir "c:worksheets"
ChDir "C:worksheets"
ActiveWorkbook.saveas Filename:= _
"C:worksheetsssworksheet_" & Worksheets("ssworksheet").Range("c6") & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub
Function PathExists(pname) As Boolean
' Returns TRUE if the path exists
Dim x As String
On Error Resume Next
x = GetAttr(pname) And 0
If Err = 0 Then PathExists = True _
Else: PathExists = False
End Function
Private Sub savebutton_Click()
Path = "c:worksheets"
If PathExists(Path) = False Then MkDir "c:worksheets"
ChDir "C:worksheets"
ActiveWorkbook.saveas Filename:= _
"C:worksheetsssworksheet_" & Worksheets("ssworksheet").Range("c6") & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub
Function PathExists(pname) As Boolean
' Returns TRUE if the path exists
Dim x As String
On Error Resume Next
x = GetAttr(pname) And 0
If Err = 0 Then PathExists = True _
Else: PathExists = False
End Function