Variable paper size for printing

MadeleineB

New Member
Joined
Sep 23, 2008
Messages
18
I'm trying to set the paper size of a worksheet by using a variable from a cell. (see code below) The variable for how many copies works but the paper size does not. If I use the following code (in green) instead on the code in red it works. HELP!

Worksheets("RAG Summary").PageSetup.PaperSize = xlPaperA3

------------------------------------------------------------------------------------------
Dim MyPaper As String
Dim MySize As String
Dim MyCopy As String

MyPaper = ThisWorkbook.Sheets("Publish").Range("N4")
MySize = "xlPaper" & MyPaper
MyCopy = ThisWorkbook.Sheets("Publish").Range("N6")

Worksheets("RAG Summary").PageSetup.PaperSize = MySize

Sheets(Array("RAG Summary", "Progress")).Select
Sheets("RAG Summary").Activate
'ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=MyCopy, Collate:=True
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hello and welcome to MrExcel.

I think that you will need to use the numerical equivalent of that constant in the code (either read from a cell or hardcoded as I have done):

Code:
MySize = 8
Worksheets("RAG Summary").PageSetup.PaperSize = MySize
 
Upvote 0
So could I do a IF statment; therefor if cell N4 = A3 it will be 8 and IF N4 = A4 it will be 9?

If yes please could you help as I don't know how to write one
 
Upvote 0
Try (changes in red):

Rich (BB code):
Dim MyPaper As String
Dim MySize As Integer
Dim MyCopy As String

MyPaper = ThisWorkbook.Sheets("Publish").Range("N4")
If MyPaper = "A4" Then
    MySize = 9
ElseIf MyPaper = "A3" Then
    MySize = 8
End If
MyCopy = ThisWorkbook.Sheets("Publish").Range("N6")

Worksheets("RAG Summary").PageSetup.PaperSize = MySize

Sheets(Array("RAG Summary", "Progress")).Select
Sheets("RAG Summary").Activate
'ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=MyCopy, Collate:=True
 
Upvote 0

Forum statistics

Threads
1,223,754
Messages
6,174,313
Members
452,554
Latest member
Louis1225

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