Export more sheets to one PDF error

otrava18

Board Regular
Joined
Feb 11, 2018
Messages
61
Hello all,

I`m not very good in VBA and i face an issue and i don`t know what can i do to resolve it.
I created a ListBox which contain some sheets name from my workbook. I have multiple selection activated. I want to be able to export this sheets to pdf.
If i use print preview or print out it shows me or printing all, like i want and is working great but if i want to export to PDF is not working. Do you have an idea what i miss or can you give me an idea how can i resolve this ?

VBA Code:
Sub Print_Sheets()
Dim i As Long, c As Long
Dim SheetArray() As String

    With ActiveSheet.ListBox1

        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                ReDim Preserve SheetArray(c)
                SheetArray(c) = .List(i)
                c = c + 1
            End If
        Next i
        
    Sheets(SheetArray()).ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\user\Desktop\xyz", Quality:=xlQualityStandard, OpenAfterPublish:=True
      
       'Sheets(SheetArray()).PrintOut
       'Sheets(SheetArray()).PrintPreview

    End With

End Sub

Thank you all !
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
First select your sheets...

VBA Code:
    Sheets(SheetArray()).Select

Then use the ExportAsFixedFormat method of the ActiveSheet object...

VBA Code:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\user\Desktop\xyz", Quality:=xlQualityStandard, OpenAfterPublish:=True

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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