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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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