having problems with layout saving to pdf

Ratigan1970

New Member
Joined
Jan 22, 2024
Messages
16
Office Version
  1. 2010
Platform
  1. Windows
hi again all in vba land
im not sure if its more vba needed to change the layout of the pdf
when i us this macro

VBA Code:
Sub SaveSelectionAsPDF()

Dim saveLocation As String
Dim myCells As Range
Set myCells = Selection



saveLocation = "D:\PAY.pdf"

  
    myCells.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "D:\PAY.pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=True, _
    OpenAfterPublish:=True
End Sub
there are pics below and there is also the link too the macro to select the ranges to save
link to post
Im trying to get all the colums on one pdf sheet

can anyone help me please
 

Attachments

  • sheet1.png
    sheet1.png
    2.7 KB · Views: 9
  • sheet2.png
    sheet2.png
    4 KB · Views: 9

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You can try so. Select cells of two columns first.
Code:
Sub Save_As_PDF()
Dim lr As Long, col As Long, i As Long
Dim ws As Worksheet
Dim fn As String
Set ws = ThisWorkbook.Worksheets("Sheet2")    <---- Change required
lr = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
col = Selection.Column
fn = ws.Cells(1, col).Value
ws.PageSetup.PrintArea = ws.Cells(1).Resize(lr, col + 1).Address
Application.ScreenUpdating = False
    For i = ws.Cells(3, ws.Columns.Count).End(xlToLeft).Column To 4 Step -1
        If i > 3 And i < col Or i > col + 1 Then ws.Cells(3, i).EntireColumn.Hidden = True
    Next i
ActiveSheet.ExportAsFixedFormat 0, "C:\PDF Saved\" & fn & ".pdf"    <---- Change required
Columns.EntireColumn.Hidden = False
Application.ScreenUpdating = True
End Sub

Artik probably has a better macro because he/she is a lot better at this than I am.
 
Upvote 0
Select the cells in the two columns and run this macro.
Code:
Sub Save_As_Pdf_2()
Dim ws As Worksheet
Dim fn As String
Set ws = ThisWorkbook.Worksheets("Sheet2")'    <---- Change required
fn = ws.Cells(1, Selection.Column).Value
ws.PageSetup.PrintTitleColumns = ws.Columns("A:C").Address
ws.PageSetup.PrintArea = Selection.Address
ws.ExportAsFixedFormat 0, "C:\PDF Saved\" & fn & ".pdf" '   <---- Change required
End Sub
 
Upvote 0
Solution
Thank you for letting us know that all is well again in your excel world.
In this case, the code from Post #3 should work for you but if you ever have a scenario where the columns at the left are not adjacent to each other, you can use the code from Post #2 by hiding the not needed columns.
 
Upvote 0

Forum statistics

Threads
1,225,726
Messages
6,186,674
Members
453,368
Latest member
xxtanka

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