ElectricSkywalker
Board Regular
- Joined
- May 27, 2002
- Messages
- 112
Hi all,
Being relative new to VBA, I am still having a few difficulties writing the stuff. I am basically learning everything I can from this web site, and a couple of books I have....yet I am still on a hugh learning curve.
Can someone please have a look at my code below, and tell me what I have to change in order to get it to do a Save AS and automatically default to C:MyDocuments (its not going to the default c:MyDocuments at the moment)
Ohh, I also have a second question......I am finding if I try attempt to re-save the file....with the same name (using the below macro)....the "File already Exists" Screen pops up. Then if press cancel...the macro saves, but my code comes up saying "File Not Saved". My Question is.....How do I edit the "File already Exists" code so that it doesn't come up.....or if it does come up...write in the "IF" statement = to edit it based on the results.
My Code is:
Sub SaveAsFileName()
Dim myFile As String
On Error Resume Next
Title = "Enter Name of File to be saved"
myFile = Range("d9") & " " & Format(Range("d14"), "dd mmmm yyyy") & " Expense Claim Form"
FileSaveName = Application.GetSaveAsFilename("C:MyDocuments" & myFile, "Microsoft Excel Workbook (*.xls),*.xls")
If FileSaveName = False Then
MsgBox "Your File was not Saved"
Exit Sub
Else
ActiveWorkbook.saveas Filename:=myFile
MsgBox (myFile & " has now been Saved")
End If
End Sub
Thanking you all in advance
Greg
Being relative new to VBA, I am still having a few difficulties writing the stuff. I am basically learning everything I can from this web site, and a couple of books I have....yet I am still on a hugh learning curve.
Can someone please have a look at my code below, and tell me what I have to change in order to get it to do a Save AS and automatically default to C:MyDocuments (its not going to the default c:MyDocuments at the moment)
Ohh, I also have a second question......I am finding if I try attempt to re-save the file....with the same name (using the below macro)....the "File already Exists" Screen pops up. Then if press cancel...the macro saves, but my code comes up saying "File Not Saved". My Question is.....How do I edit the "File already Exists" code so that it doesn't come up.....or if it does come up...write in the "IF" statement = to edit it based on the results.
My Code is:
Sub SaveAsFileName()
Dim myFile As String
On Error Resume Next
Title = "Enter Name of File to be saved"
myFile = Range("d9") & " " & Format(Range("d14"), "dd mmmm yyyy") & " Expense Claim Form"
FileSaveName = Application.GetSaveAsFilename("C:MyDocuments" & myFile, "Microsoft Excel Workbook (*.xls),*.xls")
If FileSaveName = False Then
MsgBox "Your File was not Saved"
Exit Sub
Else
ActiveWorkbook.saveas Filename:=myFile
MsgBox (myFile & " has now been Saved")
End If
End Sub
Thanking you all in advance
Greg