Run-time error '1004' While trying to generate PDF

GoCavs

New Member
Joined
Jul 11, 2017
Messages
15
Hello all,

I am encountering the following error message when I try to generate a PDF from a checkbox list of multiple sheets.
"Run-time error '1004':
Document not saved. The document may be open, or an error may have been encountered when saving."

Any help would be appreciated with helping this problem. The last section of the code is what gets highlighted when I debug:

Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\TestFolder\Book1.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True



Code:
Private Sub chbxEnter_Click()


    Dim PDFsheets As String
    Dim s As Worksheet
    PDFsheets = "Approval Form,Business Plan,Deal Worksheet,All Manager Deal Recap,Deal Recap,MEC Dealership Profile,Loyal,Mid Loyal,Non Loyal,Projected Incentive Report,MEC"
    ary = Split(PDFsheets, ",")
    
        If CheckBox1.Value = True Then
        PDFsheets = "Approval Form"
        End If
      
        If CheckBox2.Value = True Then
            If PDFsheets = "" Then
            PDFsheets = "Business Plan"
        Else
            PDFsheets = PDFsheets & ",Business Plan"
        End If
        End If
            
        If CheckBox3.Value = True Then
            If PDFsheets = "" Then
            PDFsheets = "Deal Worksheet"
        Else
            PDFsheets = PDFsheets & ",Deal Worksheet"
        End If
        End If
                  
                  
        If CheckBox4.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "Deal Recap"
        Else
            PDFsheets = PDFsheets & ",Deal Recap"
        End If
        End If
                        
        If CheckBox5.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "All Manager Deal Recap"
        Else
            PDFsheets = PDFsheets & ",All Manager Deal Recap"
        End If
        End If
                              
        If CheckBox6.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "MEC Dealership Profile"
        Else
            PDFsheets = PDFsheets & ",MEC Dealership Profile"
        End If
        End If
                              
        If CheckBox7.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "Loyal"
        Else
            PDFsheets = PDFsheets & ",Loyal"
        End If
        End If
        
        If CheckBox8.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "Mid Loyal"
        Else
            PDFsheets = PDFsheets & ",Mid Loyal"
        End If
        End If
        
        If CheckBox9.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "Non Loyal"
        Else
            PDFsheets = PDFsheets & ",Non Loyal"
        End If
        End If
        
        If CheckBox10.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "Projected Incentive Report"
        Else
            PDFsheets = PDFsheets & ",Projected Incentive Report"
        End If
        End If
        
        If CheckBox11.Value = True Then
        If PDFsheets = "" Then
           PDFsheets = "MEC"
        Else
            PDFsheets = PDFsheets & ",MEC"
        End If
        End If
        
    Sheets(ary).Select
    Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\TestFolder\Book1.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, OpenAfterPublish:=True
                                
                                




End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,214,383
Messages
6,119,198
Members
448,874
Latest member
Lancelots

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