ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Change Worksheet Properties (https://www.excelbanter.com/excel-programming/383647-how-change-worksheet-properties.html)

DevDaniel

How to Change Worksheet Properties
 
I have:
A macro to change page setup properties. The macro appears to run but
doesn't change the properties.

I want:
The macro needs to work if the names or number of worksheets changes (there
will always be a worksheet "Main" that begins with the wrong page setup
properties).
1. To change the print quality of all worksheets to 600 dpi.
2. To change the Fit to Page property of the "Main" worksheet to False.

Code snippet:
'Change print quality of all sheets to 600 dpi

ActiveWorkbook.Sheets.Select

With ActiveSheet.PageSetup
.PrintQuality = 600
End With

'Change the FitToPagesTall property on the Main worksheet to False

Sheets("Main").Select

With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = False
End With

Any suggestions?

Tom Ogilvy

How to Change Worksheet Properties
 
ActiveWorkbook.Sheets.Select

With ActiveSheet.PageSetup
.PrintQuality = 600
End With

You select all sheets, then only change properties on the activesheet.

for the most part, VBA doesn't not support grouped sheets. Loop through the
sheets and make you setting to each sheet individually.

--
Regards,
Tom Ogilvy


"DevDaniel" wrote:

I have:
A macro to change page setup properties. The macro appears to run but
doesn't change the properties.

I want:
The macro needs to work if the names or number of worksheets changes (there
will always be a worksheet "Main" that begins with the wrong page setup
properties).
1. To change the print quality of all worksheets to 600 dpi.
2. To change the Fit to Page property of the "Main" worksheet to False.

Code snippet:
'Change print quality of all sheets to 600 dpi

ActiveWorkbook.Sheets.Select

With ActiveSheet.PageSetup
.PrintQuality = 600
End With

'Change the FitToPagesTall property on the Main worksheet to False

Sheets("Main").Select

With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = False
End With

Any suggestions?


Vergel Adriano

How to Change Worksheet Properties
 
If I understand correctly, you want to apply the settings to all sheets.
Try this

Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
With sht.PageSetup
.PrintQuality = 600
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Next sht


"DevDaniel" wrote:

I have:
A macro to change page setup properties. The macro appears to run but
doesn't change the properties.

I want:
The macro needs to work if the names or number of worksheets changes (there
will always be a worksheet "Main" that begins with the wrong page setup
properties).
1. To change the print quality of all worksheets to 600 dpi.
2. To change the Fit to Page property of the "Main" worksheet to False.

Code snippet:
'Change print quality of all sheets to 600 dpi

ActiveWorkbook.Sheets.Select

With ActiveSheet.PageSetup
.PrintQuality = 600
End With

'Change the FitToPagesTall property on the Main worksheet to False

Sheets("Main").Select

With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = False
End With

Any suggestions?



All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com