No Error But also not executing

AFidytek

New Member
Joined
Jun 5, 2019
Messages
23
Hi all

Me again

So I have another one that doesn't give me any errors, but it is also not executing the code.

It gives the correct msgbox and filename but when pressing save absolutely nothing happens. It doesn't actually execute the code.

Not sure why.

Private Sub CommandButton3_Click()
answer = msgbox("Do you want to export the application to PDF?", vbYesNo + vbQuestion, "Export Application to PDF")
If answer = vbYes Then
filesSaveName = Application.GetSaveAsFilename(Sheet49.Range("P13"), fileFilter:="PDF (*.pdf), *.pdf")
If fileSaveName <> False Then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
End If
End Sub



I am using the exact code in another document and it works perfectly. The only difference is Button and CommandButton. Can that be it? Here is the other documents code that works.


Sub Button3_Click()
answer = MsgBox("Do you want to export to PDF?", vbYesNo + vbQuestion, "Export to PDF")
If answer = vbYes Then
fileSaveName = Application.GetSaveAsFilename(Sheet4.Range("D39"), fileFilter:="PDF (*.pdf), *.pdf")
If fileSaveName <> False Then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
End If
End Sub

Thank you!

A
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You've misspelt filesSaveName.

Try this, and add Option Explicit at the top of the module to help avoid the same thing happening again.
Code:
Option Explicit

Private Sub CommandButton3_Click()
Dim Answer As VbMsgBoxResult
Dim fileSaveName As Variant

    Answer = MsgBox("Do you want to export the application to PDF?", vbYesNo + vbQuestion, "Export Application to PDF")
    If Answer = vbYes Then
        fileSaveName = Application.GetSaveAsFilename(Sheet49.Range("P13"), fileFilter:="PDF (*.pdf), *.pdf")
        If fileSaveName <> False Then
            ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
        End If
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,937
Messages
6,181,858
Members
453,068
Latest member
DCD1872

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