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
 

GoCavs

New Member
Joined
Jul 11, 2017
Messages
15
*Also I do not have any PDFs opened or anything else running on my PC
 

Forum statistics

Threads
1,081,708
Messages
5,360,781
Members
400,595
Latest member
T_Dubs

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top