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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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