Troubles saving using ActiveX Command Button

JMcCauley

New Member
Joined
Jan 7, 2014
Messages
7
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:

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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,650
Messages
6,126,019
Members
449,280
Latest member
Miahr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top