techsupport1
Registered User.
- Local time
- Today, 11:35
- Joined
- Aug 24, 2011
- Messages
- 19
VBA - Save as certain filename when "save" or "save as" is pressed
Hi all,
I'm working on a file that needs to be saved as a certain filename (ex. John12week5.xls) in a location chosen by the user. I'm having some issues in "idiot-proofing" the operation.
I have developed code to complete the save alright that can be run off of a macro button. However I'd like to make it run when "save as" or "save" is pressed in the toolbar so the file is always properly saved.
If I try putting the macro's code directly into the workbook on the "before save" event (see code 1 below) but receive the following error
"Compile error, can't assign to read-only property"
I also tried calling the function I used to save in the workbook (see code 2 below) but that had more issues. It would go through fine but when I went to save with a strict filename, it initiates the "beforesave" event and starts the process again.
I'm using 2003 if that makes any difference. Any help is greatly appreciated.
Hi all,
I'm working on a file that needs to be saved as a certain filename (ex. John12week5.xls) in a location chosen by the user. I'm having some issues in "idiot-proofing" the operation.
I have developed code to complete the save alright that can be run off of a macro button. However I'd like to make it run when "save as" or "save" is pressed in the toolbar so the file is always properly saved.
If I try putting the macro's code directly into the workbook on the "before save" event (see code 1 below) but receive the following error
"Compile error, can't assign to read-only property"
I also tried calling the function I used to save in the workbook (see code 2 below) but that had more issues. It would go through fine but when I went to save with a strict filename, it initiates the "beforesave" event and starts the process again.
I'm using 2003 if that makes any difference. Any help is greatly appreciated.
Code:
Option Explicit
Public CompletePath As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
''Macro goes here
Code:
Dim CompeltePath As String
MsgBox "Break."
CompletePath = Module1.SavingMacro
ActiveWorkbook.SaveAs CompletePath
End Sub
Last edited: