VBA is not printing to PDF correctly

misterno

Board Regular
Joined
Mar 16, 2009
Messages
78
Here is my code

VBA is not printing the correct area instead it is printing C3:X212. (The correct area is "$c$3:$AA$212")

Can someone help?

Code:
Sub test() 
 On Error Resume Next
 
 Dim rootDir As String


 rootDir = "M:\dept\SLNGNA\Gas LPM\Structuring\Daily Report\Daily PDF Files\New England Gas Fundamentals"


 Sheets(Array("New England Balances", "LDCs MA")).Select
 
 Sheets("New England Balances").Activate
 ActiveSheet.PageSetup.PrintArea = "$c$3:$AA$212"
 Range("$c$3:$AA$212").Select
 
 Sheets("LDCs MA").Activate
 ActiveSheet.PageSetup.PrintArea = "$b$2:$x$135"
 Range("$b$2:$x$135").Select
 
 Selection.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="m:\Dept\SLNGNA\Gas LPM\Structuring\Daily Report\Daily PDF Files\New England Gas Fundamentals_" & VBA.Format(Date, "MMDDYYYY") & ".pdf", _
    Quality:=xlQualityStandard, _
    OpenAfterPublish:=True
     
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Here is my code

VBA is not printing the correct area instead it is printing C3:X212. (The correct area is "$c$3:$AA$212")

Can someone help?

Code:
Sub test() 
 On Error Resume Next
 
 Dim rootDir As String


 rootDir = "M:\dept\SLNGNA\Gas LPM\Structuring\Daily Report\Daily PDF Files\New England Gas Fundamentals"


 Sheets(Array("New England Balances", "LDCs MA")).Select
 
[COLOR="#0000CD"] Sheets("New England Balances").Activate[/COLOR] ActiveSheet.PageSetup.[COLOR="#FF0000"]PrintArea = "$c$3:$AA$212"[/COLOR] Range("$c$3:$AA$212").Select
 
[COLOR="#0000CD"] Sheets("LDCs MA").Activate[/COLOR]
 ActiveSheet.PageSetup.[COLOR="#FF0000"][/COLOR][COLOR="#FF0000"]PrintArea = "$b$2:$x$135"[/COLOR] Range("$b$2:$x$135").Select
 
 Selection.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="m:\Dept\SLNGNA\Gas LPM\Structuring\Daily Report\Daily PDF Files\New England Gas Fundamentals_" & VBA.Format(Date, "MMDDYYYY") & ".pdf", _
    Quality:=xlQualityStandard, _
    OpenAfterPublish:=True
     
End Sub
It is doing what it is told to do. The code switches sheets before a print instruction is given for the first sheet. but I don't see where this code tells it to print anything.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,730
Members
449,465
Latest member
TAKLAM

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