VBA Excel to Pdf

s3v3r

New Member
Joined
Sep 28, 2018
Messages
1
Hi

Thanks beforehand.

My problem is that im trying to create a pdf from an excel sheet but I need to create a single pdf with a single page with the same sheet, cutting ranges from the excel and and pasting them on top of another... they are different tables.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Is this what you want

Code:
Sub copyTablesPDF()
    Dim ws As Worksheet:    Set ws = Sheets("Sheet1")
'copy tables
    Sheets("Sheet2").ListObjects("tbl_manning").Range.Copy ws.Range("A1")
    Sheets("Sheet4").ListObjects("tbl_result").Range.Copy ws.Range("A" & Rows.Count).End(xlUp).Offset(2)
    Sheets("Sheet3").ListObjects("tbl_cost").Range.Copy ws.Range("A" & Rows.Count).End(xlUp).Offset(2)
'save sheet1 to pdf
    ws.UsedRange.ExportAsFixedFormat Type:=xlTypePDF, Filename:="c:\testarea\tables.pdf"
End Sub

they are different tables
The above code assumes that your ranges are Excel Tables (ie created with Insert \ Table)

If they are they tabulated ranges
instead of
Code:
    Sheets("Sheet2").ListObjects("tbl_manning").Range.Copy ws.Range("A1")
use this method
Code:
    Sheets("Sheet2").Range("A1:D10").Copy ws.Range("A1")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,743
Members
449,094
Latest member
dsharae57

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