A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Page set up for all worksheets



 
 
Thread Tools Display Modes
  #1  
Old October 30th 09, 01:58 PM posted to microsoft.public.excel.programming
Jodie
external usenet poster
 
Posts: 72
Default Page set up for all worksheets

Hello,

I am trying to run the following macro for all sheets in a workbook:

Sub VBAMacro()
Cells.Select
Range("D1").Activate
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.PrintGridlines = True
.Orientation = xlLandscape
.PrintTitleRows = ""
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 5
End With
ActiveWorkbook.Save
End Sub

How can I make it work?
--
Thank you, Jodie
Ads
  #2  
Old October 30th 09, 02:08 PM posted to microsoft.public.excel.programming
Patrick Molloy[_2_]
external usenet poster
 
Posts: 1,298
Default Page set up for all worksheets

sub Main()
dim ws as worksheet
for each ws in worksheets
ws.activate
VBAMacro
next
End Sub

"Jodie" wrote:

> Hello,
>
> I am trying to run the following macro for all sheets in a workbook:
>
> Sub VBAMacro()
> Cells.Select
> Range("D1").Activate
> ActiveSheet.PageSetup.PrintArea = ""
> With ActiveSheet.PageSetup
> .PrintGridlines = True
> .Orientation = xlLandscape
> .PrintTitleRows = ""
> .Zoom = False
> .FitToPagesWide = 1
> .FitToPagesTall = 5
> End With
> ActiveWorkbook.Save
> End Sub
>
> How can I make it work?
> --
> Thank you, Jodie

  #3  
Old October 30th 09, 02:25 PM posted to microsoft.public.excel.programming
John
external usenet poster
 
Posts: 2,069
Default Page set up for all worksheets

not tested but something like following should do what you want.

Sub VBAMacro()
Dim ws As Worksheet

Application.DisplayAlerts = False

With ActiveWorkbook

For Each ws In .Worksheets

With ws.PageSetup

.PrintArea = ""
.PrintGridlines = True
.Orientation = xlLandscape
.PrintTitleRows = ""
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 5

End With

Next ws

.Save

End With

Application.DisplayAlerts = True

End Sub
--
jb


"Jodie" wrote:

> Hello,
>
> I am trying to run the following macro for all sheets in a workbook:
>
> Sub VBAMacro()
> Cells.Select
> Range("D1").Activate
> ActiveSheet.PageSetup.PrintArea = ""
> With ActiveSheet.PageSetup
> .PrintGridlines = True
> .Orientation = xlLandscape
> .PrintTitleRows = ""
> .Zoom = False
> .FitToPagesWide = 1
> .FitToPagesTall = 5
> End With
> ActiveWorkbook.Save
> End Sub
>
> How can I make it work?
> --
> Thank you, Jodie

  #4  
Old October 30th 09, 02:54 PM posted to microsoft.public.excel.programming
Jodie
external usenet poster
 
Posts: 72
Default Page set up for all worksheets

This works great. Thank you both. Now, I need to hide columns in these same
worksheets. Are either of you up for that. Idealy, I would like to hide any
columns that are blank after row 1. If that is not possible, I could select
a specific column that I know is blank, column P.
--
Thank you, Jodie


"john" wrote:

> not tested but something like following should do what you want.
>
> Sub VBAMacro()
> Dim ws As Worksheet
>
> Application.DisplayAlerts = False
>
> With ActiveWorkbook
>
> For Each ws In .Worksheets
>
> With ws.PageSetup
>
> .PrintArea = ""
> .PrintGridlines = True
> .Orientation = xlLandscape
> .PrintTitleRows = ""
> .Zoom = False
> .FitToPagesWide = 1
> .FitToPagesTall = 5
>
> End With
>
> Next ws
>
> .Save
>
> End With
>
> Application.DisplayAlerts = True
>
> End Sub
> --
> jb
>
>
> "Jodie" wrote:
>
> > Hello,
> >
> > I am trying to run the following macro for all sheets in a workbook:
> >
> > Sub VBAMacro()
> > Cells.Select
> > Range("D1").Activate
> > ActiveSheet.PageSetup.PrintArea = ""
> > With ActiveSheet.PageSetup
> > .PrintGridlines = True
> > .Orientation = xlLandscape
> > .PrintTitleRows = ""
> > .Zoom = False
> > .FitToPagesWide = 1
> > .FitToPagesTall = 5
> > End With
> > ActiveWorkbook.Save
> > End Sub
> >
> > How can I make it work?
> > --
> > Thank you, Jodie

  #5  
Old October 30th 09, 03:59 PM posted to microsoft.public.excel.programming
John
external usenet poster
 
Posts: 2,069
Default Page set up for all worksheets

Hi jodie,

see if this does what you want (assumes using 2003)

Sub HideEmptyCols()

Dim iCol As Integer
Dim ws As Worksheet

'Excel 2003

Application.ScreenUpdating = False

For Each ws In Worksheets


For iCol = 256 To ws.Range("IV1").End(xlToLeft).Offset(0,
1).Column Step -1

If IsEmpty(ws.Cells(65536, iCol)) And _
IsEmpty(ws.Cells(1, iCol)) Then

If iCol > 1 Then

ws.Cells(iCol, iCol).EntireColumn.Hidden = True

Else

ws.Cells(iCol, iCol).EntireColumn.Hidden = False

End If

End If

Next iCol

Next ws

Application.ScreenUpdating = True

End Sub
--
jb


"Jodie" wrote:

> This works great. Thank you both. Now, I need to hide columns in these same
> worksheets. Are either of you up for that. Idealy, I would like to hide any
> columns that are blank after row 1. If that is not possible, I could select
> a specific column that I know is blank, column P.
> --
> Thank you, Jodie
>
>
> "john" wrote:
>
> > not tested but something like following should do what you want.
> >
> > Sub VBAMacro()
> > Dim ws As Worksheet
> >
> > Application.DisplayAlerts = False
> >
> > With ActiveWorkbook
> >
> > For Each ws In .Worksheets
> >
> > With ws.PageSetup
> >
> > .PrintArea = ""
> > .PrintGridlines = True
> > .Orientation = xlLandscape
> > .PrintTitleRows = ""
> > .Zoom = False
> > .FitToPagesWide = 1
> > .FitToPagesTall = 5
> >
> > End With
> >
> > Next ws
> >
> > .Save
> >
> > End With
> >
> > Application.DisplayAlerts = True
> >
> > End Sub
> > --
> > jb
> >
> >
> > "Jodie" wrote:
> >
> > > Hello,
> > >
> > > I am trying to run the following macro for all sheets in a workbook:
> > >
> > > Sub VBAMacro()
> > > Cells.Select
> > > Range("D1").Activate
> > > ActiveSheet.PageSetup.PrintArea = ""
> > > With ActiveSheet.PageSetup
> > > .PrintGridlines = True
> > > .Orientation = xlLandscape
> > > .PrintTitleRows = ""
> > > .Zoom = False
> > > .FitToPagesWide = 1
> > > .FitToPagesTall = 5
> > > End With
> > > ActiveWorkbook.Save
> > > End Sub
> > >
> > > How can I make it work?
> > > --
> > > Thank you, Jodie

  #6  
Old October 30th 09, 05:13 PM posted to microsoft.public.excel.programming
Jodie
external usenet poster
 
Posts: 72
Default Page set up for all worksheets

John, it worked except it still left the columns with a header in row 1 even
though there is nothing else in the column. Also, I realized that what I
should have asked for was to hide the column if all of the cells are blank or
have a value of 0 (zero). Is this possible? I appreciate your help.
--
Thank you, Jodie


"john" wrote:

> Hi jodie,
>
> see if this does what you want (assumes using 2003)
>
> Sub HideEmptyCols()
>
> Dim iCol As Integer
> Dim ws As Worksheet
>
> 'Excel 2003
>
> Application.ScreenUpdating = False
>
> For Each ws In Worksheets
>
>
> For iCol = 256 To ws.Range("IV1").End(xlToLeft).Offset(0,
> 1).Column Step -1
>
> If IsEmpty(ws.Cells(65536, iCol)) And _
> IsEmpty(ws.Cells(1, iCol)) Then
>
> If iCol > 1 Then
>
> ws.Cells(iCol, iCol).EntireColumn.Hidden = True
>
> Else
>
> ws.Cells(iCol, iCol).EntireColumn.Hidden = False
>
> End If
>
> End If
>
> Next iCol
>
> Next ws
>
> Application.ScreenUpdating = True
>
> End Sub
> --
> jb
>
>
> "Jodie" wrote:
>
> > This works great. Thank you both. Now, I need to hide columns in these same
> > worksheets. Are either of you up for that. Idealy, I would like to hide any
> > columns that are blank after row 1. If that is not possible, I could select
> > a specific column that I know is blank, column P.
> > --
> > Thank you, Jodie
> >
> >
> > "john" wrote:
> >
> > > not tested but something like following should do what you want.
> > >
> > > Sub VBAMacro()
> > > Dim ws As Worksheet
> > >
> > > Application.DisplayAlerts = False
> > >
> > > With ActiveWorkbook
> > >
> > > For Each ws In .Worksheets
> > >
> > > With ws.PageSetup
> > >
> > > .PrintArea = ""
> > > .PrintGridlines = True
> > > .Orientation = xlLandscape
> > > .PrintTitleRows = ""
> > > .Zoom = False
> > > .FitToPagesWide = 1
> > > .FitToPagesTall = 5
> > >
> > > End With
> > >
> > > Next ws
> > >
> > > .Save
> > >
> > > End With
> > >
> > > Application.DisplayAlerts = True
> > >
> > > End Sub
> > > --
> > > jb
> > >
> > >
> > > "Jodie" wrote:
> > >
> > > > Hello,
> > > >
> > > > I am trying to run the following macro for all sheets in a workbook:
> > > >
> > > > Sub VBAMacro()
> > > > Cells.Select
> > > > Range("D1").Activate
> > > > ActiveSheet.PageSetup.PrintArea = ""
> > > > With ActiveSheet.PageSetup
> > > > .PrintGridlines = True
> > > > .Orientation = xlLandscape
> > > > .PrintTitleRows = ""
> > > > .Zoom = False
> > > > .FitToPagesWide = 1
> > > > .FitToPagesTall = 5
> > > > End With
> > > > ActiveWorkbook.Save
> > > > End Sub
> > > >
> > > > How can I make it work?
> > > > --
> > > > Thank you, Jodie

  #7  
Old October 30th 09, 09:48 PM posted to microsoft.public.excel.programming
John
external usenet poster
 
Posts: 2,069
Default Page set up for all worksheets

Hi jodie,
sorry for slow reply, went out for evening.

see if this mod helps:

Sub HideEmptyCols()

Dim iCol As Integer
Dim ws As Worksheet
Dim rRange As Range

'Excel 2003

Application.ScreenUpdating = False


For Each ws In Worksheets

For iCol = 256 To 2 Step -1

If Application.WorksheetFunction.Sum(ws.Range(ws.Cell s(2, iCol), _

ws.Cells(65536, iCol))) = 0 Then

ws.Cells(, iCol).EntireColumn.Hidden = True

End If

Next iCol

Next ws

Application.ScreenUpdating = True

End Sub
--
jb


"Jodie" wrote:

> John, it worked except it still left the columns with a header in row 1 even
> though there is nothing else in the column. Also, I realized that what I
> should have asked for was to hide the column if all of the cells are blank or
> have a value of 0 (zero). Is this possible? I appreciate your help.
> --
> Thank you, Jodie
>
>
> "john" wrote:
>
> > Hi jodie,
> >
> > see if this does what you want (assumes using 2003)
> >
> > Sub HideEmptyCols()
> >
> > Dim iCol As Integer
> > Dim ws As Worksheet
> >
> > 'Excel 2003
> >
> > Application.ScreenUpdating = False
> >
> > For Each ws In Worksheets
> >
> >
> > For iCol = 256 To ws.Range("IV1").End(xlToLeft).Offset(0,
> > 1).Column Step -1
> >
> > If IsEmpty(ws.Cells(65536, iCol)) And _
> > IsEmpty(ws.Cells(1, iCol)) Then
> >
> > If iCol > 1 Then
> >
> > ws.Cells(iCol, iCol).EntireColumn.Hidden = True
> >
> > Else
> >
> > ws.Cells(iCol, iCol).EntireColumn.Hidden = False
> >
> > End If
> >
> > End If
> >
> > Next iCol
> >
> > Next ws
> >
> > Application.ScreenUpdating = True
> >
> > End Sub
> > --
> > jb
> >
> >
> > "Jodie" wrote:
> >
> > > This works great. Thank you both. Now, I need to hide columns in these same
> > > worksheets. Are either of you up for that. Idealy, I would like to hide any
> > > columns that are blank after row 1. If that is not possible, I could select
> > > a specific column that I know is blank, column P.
> > > --
> > > Thank you, Jodie
> > >
> > >
> > > "john" wrote:
> > >
> > > > not tested but something like following should do what you want.
> > > >
> > > > Sub VBAMacro()
> > > > Dim ws As Worksheet
> > > >
> > > > Application.DisplayAlerts = False
> > > >
> > > > With ActiveWorkbook
> > > >
> > > > For Each ws In .Worksheets
> > > >
> > > > With ws.PageSetup
> > > >
> > > > .PrintArea = ""
> > > > .PrintGridlines = True
> > > > .Orientation = xlLandscape
> > > > .PrintTitleRows = ""
> > > > .Zoom = False
> > > > .FitToPagesWide = 1
> > > > .FitToPagesTall = 5
> > > >
> > > > End With
> > > >
> > > > Next ws
> > > >
> > > > .Save
> > > >
> > > > End With
> > > >
> > > > Application.DisplayAlerts = True
> > > >
> > > > End Sub
> > > > --
> > > > jb
> > > >
> > > >
> > > > "Jodie" wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I am trying to run the following macro for all sheets in a workbook:
> > > > >
> > > > > Sub VBAMacro()
> > > > > Cells.Select
> > > > > Range("D1").Activate
> > > > > ActiveSheet.PageSetup.PrintArea = ""
> > > > > With ActiveSheet.PageSetup
> > > > > .PrintGridlines = True
> > > > > .Orientation = xlLandscape
> > > > > .PrintTitleRows = ""
> > > > > .Zoom = False
> > > > > .FitToPagesWide = 1
> > > > > .FitToPagesTall = 5
> > > > > End With
> > > > > ActiveWorkbook.Save
> > > > > End Sub
> > > > >
> > > > > How can I make it work?
> > > > > --
> > > > > Thank you, Jodie

  #8  
Old November 2nd 09, 04:31 PM posted to microsoft.public.excel.programming
Jodie
external usenet poster
 
Posts: 72
Default Page set up for all worksheets

Hi John, I hope you had a fun weekend.

I tried this out and it is hiding my columns that are blank and the colums
that have an alpha value. The columns with zero are still present. Is there
something that I can change that will keep the alpha columns and hide the
zero columns?
--
Thank you, Jodie


"john" wrote:

> Hi jodie,
> sorry for slow reply, went out for evening.
>
> see if this mod helps:
>
> Sub HideEmptyCols()
>
> Dim iCol As Integer
> Dim ws As Worksheet
> Dim rRange As Range
>
> 'Excel 2003
>
> Application.ScreenUpdating = False
>
>
> For Each ws In Worksheets
>
> For iCol = 256 To 2 Step -1
>
> If Application.WorksheetFunction.Sum(ws.Range(ws.Cell s(2, iCol), _
>
> ws.Cells(65536, iCol))) = 0 Then
>
> ws.Cells(, iCol).EntireColumn.Hidden = True
>
> End If
>
> Next iCol
>
> Next ws
>
> Application.ScreenUpdating = True
>
> End Sub
> --
> jb
>
>
> "Jodie" wrote:
>
> > John, it worked except it still left the columns with a header in row 1 even
> > though there is nothing else in the column. Also, I realized that what I
> > should have asked for was to hide the column if all of the cells are blank or
> > have a value of 0 (zero). Is this possible? I appreciate your help.
> > --
> > Thank you, Jodie
> >
> >
> > "john" wrote:
> >
> > > Hi jodie,
> > >
> > > see if this does what you want (assumes using 2003)
> > >
> > > Sub HideEmptyCols()
> > >
> > > Dim iCol As Integer
> > > Dim ws As Worksheet
> > >
> > > 'Excel 2003
> > >
> > > Application.ScreenUpdating = False
> > >
> > > For Each ws In Worksheets
> > >
> > >
> > > For iCol = 256 To ws.Range("IV1").End(xlToLeft).Offset(0,
> > > 1).Column Step -1
> > >
> > > If IsEmpty(ws.Cells(65536, iCol)) And _
> > > IsEmpty(ws.Cells(1, iCol)) Then
> > >
> > > If iCol > 1 Then
> > >
> > > ws.Cells(iCol, iCol).EntireColumn.Hidden = True
> > >
> > > Else
> > >
> > > ws.Cells(iCol, iCol).EntireColumn.Hidden = False
> > >
> > > End If
> > >
> > > End If
> > >
> > > Next iCol
> > >
> > > Next ws
> > >
> > > Application.ScreenUpdating = True
> > >
> > > End Sub
> > > --
> > > jb
> > >
> > >
> > > "Jodie" wrote:
> > >
> > > > This works great. Thank you both. Now, I need to hide columns in these same
> > > > worksheets. Are either of you up for that. Idealy, I would like to hide any
> > > > columns that are blank after row 1. If that is not possible, I could select
> > > > a specific column that I know is blank, column P.
> > > > --
> > > > Thank you, Jodie
> > > >
> > > >
> > > > "john" wrote:
> > > >
> > > > > not tested but something like following should do what you want.
> > > > >
> > > > > Sub VBAMacro()
> > > > > Dim ws As Worksheet
> > > > >
> > > > > Application.DisplayAlerts = False
> > > > >
> > > > > With ActiveWorkbook
> > > > >
> > > > > For Each ws In .Worksheets
> > > > >
> > > > > With ws.PageSetup
> > > > >
> > > > > .PrintArea = ""
> > > > > .PrintGridlines = True
> > > > > .Orientation = xlLandscape
> > > > > .PrintTitleRows = ""
> > > > > .Zoom = False
> > > > > .FitToPagesWide = 1
> > > > > .FitToPagesTall = 5
> > > > >
> > > > > End With
> > > > >
> > > > > Next ws
> > > > >
> > > > > .Save
> > > > >
> > > > > End With
> > > > >
> > > > > Application.DisplayAlerts = True
> > > > >
> > > > > End Sub
> > > > > --
> > > > > jb
> > > > >
> > > > >
> > > > > "Jodie" wrote:
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > I am trying to run the following macro for all sheets in a workbook:
> > > > > >
> > > > > > Sub VBAMacro()
> > > > > > Cells.Select
> > > > > > Range("D1").Activate
> > > > > > ActiveSheet.PageSetup.PrintArea = ""
> > > > > > With ActiveSheet.PageSetup
> > > > > > .PrintGridlines = True
> > > > > > .Orientation = xlLandscape
> > > > > > .PrintTitleRows = ""
> > > > > > .Zoom = False
> > > > > > .FitToPagesWide = 1
> > > > > > .FitToPagesTall = 5
> > > > > > End With
> > > > > > ActiveWorkbook.Save
> > > > > > End Sub
> > > > > >
> > > > > > How can I make it work?
> > > > > > --
> > > > > > Thank you, Jodie

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Summary page for 12 worksheets ACM Excel Discussion (Misc queries) 11 January 15th 08 12:06 PM
Printing several worksheets as on page Coenie Brand Excel Programming 2 June 29th 07 02:38 PM
Add page numbers to multiple worksheets without changing page setu alatona Excel Discussion (Misc queries) 2 March 16th 07 07:23 PM
Printing multiple page worksheets on 1 single page Hope Excel Discussion (Misc queries) 1 January 7th 07 03:56 AM
How do I use 2 worksheets in 1 page merry_fay Excel Worksheet Functions 2 June 1st 05 03:06 PM


All times are GMT +1. The time now is 03:05 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2004-2013 ExcelBanter.
The comments are property of their posters.