Macro to save file as PDF saves full sheet

Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
445
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I have this overview at the moment:
1651819172017.png


If I manually choose to save my file as a PDF, it works fine and I get just 1 page with the overview above.

However, I have the following VBA code to save my file as a PDF:

VBA Code:
Option Explicit

Sub SaveFileWithMacro()

Dim Path As String
Dim fn As String
Path = "S:\COMPANY\TG_FDSL\DS_COMMON\PRIVATE FOLDER\18- PRIVATE SUBFOLDER\Tracking\PDF files\"
fn = Range("A61")
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Path & fn & ".pdf"

End Sub

But when I save my file with this macro, it saves the entire sheet and I get 4 pages of PDF, rather than the limited view I have set it to above.

Has anybody tried this before? Does anybody have a solution? @Fluff is this a bug maybe?

Thank you!

Kind regards,
Jyggalag
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I have something similar but it works with print areas try adding
VBA Code:
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=False
 
Upvote 0
VBA Code:
Option Explicit

Sub SaveFileWithMacro()

Dim Path As String
Dim fn As String
Path = "S:\COMPANY\TG_FDSL\DS_COMMON\PRIVATE FOLDER\18- PRIVATE SUBFOLDER\Tracking\PDF files\"
fn = Range("A61")
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Path & fn & ".pdf",_
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 
Upvote 0
H
VBA Code:
Option Explicit

Sub SaveFileWithMacro()

Dim Path As String
Dim fn As String
Path = "S:\COMPANY\TG_FDSL\DS_COMMON\PRIVATE FOLDER\18- PRIVATE SUBFOLDER\Tracking\PDF files\"
fn = Range("A61")
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Path & fn & ".pdf",_
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
Hi!

Thank you so much!

I am for some reason getting this error in the code, any idea how to fix? @Fluff @RoryA maybe?

1651844923553.png
 
Upvote 0
UPDATE! It works now with this being the full code:

VBA Code:
Option Explicit

Sub SaveFileWithMacro()

Dim Path As String
Dim fn As String
Path = "S:\PATH\Tracking\PDF files\"
fn = Range("A61")
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
     Filename:=Path & fn & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=False

End Sub

HOWEVER, when I run the macro, it still saves all 4 pages of the PDF and not the marked area as I want it to :( Any idea why or how to fix?
 

Attachments

  • 1651844996122.png
    1651844996122.png
    10.9 KB · Views: 4
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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