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 fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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