Hello world,
I am attempting to use a single command button to save two sheets using VBA, but Excel (2010) keeps crashing on me. I'm new to VBA, have learned a ton from the members on here, and I know that I must be doing something wrong.
I would like to use a command button located in Sheet1, that when clicked, saves Sheet1 with the file name as: the value of cell C3_C2_C4.xlsm and simultaneously saves Sheet4 with the same name, but as a pdf.
Here's my code that I've somewhat pieced together:
Other than me being a rookie with very little VBA experience, can anyone see why it's crashing?
Thanks for all your help!
JM
I am attempting to use a single command button to save two sheets using VBA, but Excel (2010) keeps crashing on me. I'm new to VBA, have learned a ton from the members on here, and I know that I must be doing something wrong.
I would like to use a command button located in Sheet1, that when clicked, saves Sheet1 with the file name as: the value of cell C3_C2_C4.xlsm and simultaneously saves Sheet4 with the same name, but as a pdf.
Here's my code that I've somewhat pieced together:
Code:
Sub CommandButton1()
If CommandButton1() = True Then
ActiveWorkbook.SaveAs Filename:= _
"S:\Students\2015\" & Sheets(1).Range("C3") & "_" & Sheets(1).Range("C2") & "_" & Sheets1.Range("C4") & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Sheets("Sheet4").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"S:\Students\2015\" & Sheets(1).Range("C3") & "_" & Sheets(1).Range("C2") & "_" & Sheets(1).Range("C4") & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End If
End Sub
Other than me being a rookie with very little VBA experience, can anyone see why it's crashing?
Thanks for all your help!
JM