jfgoodhew1
New Member
- Joined
- Oct 16, 2012
- Messages
- 19
Hi Guys,
I wrote a beforesave event in the Workbook module in Excel 2010 VBA, and the save fails. I've simplified it, commented out my entire block and written a lovely simple one (shown here), and it still fails. Any help much appreciated!
Notes:
Every time I click Save I get False as ThisWorkbook.Saved and "There was an error saving the spreadsheet."
Save As does the same, and I tried putting code into a BeforeClose event to save it - no joy.
Any clues why this might be? What have I screwed up?? ... Been staring at this for ages.
I wrote a beforesave event in the Workbook module in Excel 2010 VBA, and the save fails. I've simplified it, commented out my entire block and written a lovely simple one (shown here), and it still fails. Any help much appreciated!
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'First checks state of boolean
'Prevents save twice behaviour in VBA
'Boolean set to true on Workbook_Open event
Cancel = True
If ThisWorkbook.EnableBeforeSave = True Then
ThisWorkbook.SaveAs "2014-09-08-INV.xlsm"
MsgBox ThisWorkbook.Saved & " on save"
Else
MsgBox "ThisWorkbook.EnableBeforeSave is " & ThisWorkbook.EnableBeforeSave
End If
If ThisWorkbook.Saved = False Then MsgBox "There was an error saving the spreadsheet."
End Sub
Notes:
Every time I click Save I get False as ThisWorkbook.Saved and "There was an error saving the spreadsheet."
Save As does the same, and I tried putting code into a BeforeClose event to save it - no joy.
Any clues why this might be? What have I screwed up?? ... Been staring at this for ages.