PC Review


Reply
Thread Tools Rate Thread

Changing the Zoom Property of a WorkBook without using an Array

 
 
spences10
Guest
Posts: n/a
 
      14th Jan 2007
Hi,

I am trying to write a bit of code that changes the zoom property of a
whole work book. Rather than use an array [as there are 40+ worksheets]
I want to use 'For Each' statement like

Sub ChangeZoom55()

Application.ScreenUpdating = False
Dim Sh As Worksheet

For Each Sh In Worksheets
Sh.Zoom = 55
Next

Application.ScreenUpdating = True

Sub Function

There is the added frustration of hidden worksheets, so I am not sure
if I have to run a separate bit of code to un hide the hidden sheets,
if I do have to do this is there a way in which I can hide all the
sheets which were originally hidden but not the sheets that were
visible to start with.

Any help much appreciated. Scott
= )

 
Reply With Quote
 
 
 
 
Helmut Weber
Guest
Posts: n/a
 
      14th Jan 2007
Hi Scott,

though, with Excel, I am on strange territory,
I think, it is the same as with Word-documents.
Worksheets as well as Word-documents don't have
a zoom property at all. Zoom is a property of a window.

Dim oWnd As Window
Set oWnd = ActiveWindow
oWnd.Zoom = 55

So if there is no window, as with a hidden worksheet,
it might be impossible to set a zoom.

The Excel-experts around will correct me, if I am wrong.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
Reply With Quote
 
Ken Johnson
Guest
Posts: n/a
 
      14th Jan 2007

spences10 wrote:
> Hi,
>
> I am trying to write a bit of code that changes the zoom property of a
> whole work book. Rather than use an array [as there are 40+ worksheets]
> I want to use 'For Each' statement like
>
> Sub ChangeZoom55()
>
> Application.ScreenUpdating = False
> Dim Sh As Worksheet
>
> For Each Sh In Worksheets
> Sh.Zoom = 55
> Next
>
> Application.ScreenUpdating = True
>
> Sub Function
>
> There is the added frustration of hidden worksheets, so I am not sure
> if I have to run a separate bit of code to un hide the hidden sheets,
> if I do have to do this is there a way in which I can hide all the
> sheets which were originally hidden but not the sheets that were
> visible to start with.
>
> Any help much appreciated. Scott
> = )


Hi Scott,

Helmut's right.

I tried...

Public Sub zoomAll()
Dim Sht As Worksheet
For Each Sht In ActiveWorkbook.Worksheets
Sht.Activate
ActiveWindow.Zoom = 50
Next Sht
End Sub

which worked.

Ken Johnson

 
Reply With Quote
 
spences10
Guest
Posts: n/a
 
      15th Jan 2007
Faaaantastic,

thank you both



Ken Johnson wrote:
> spences10 wrote:
> > Hi,
> >
> > I am trying to write a bit of code that changes the zoom property of a
> > whole work book. Rather than use an array [as there are 40+ worksheets]
> > I want to use 'For Each' statement like
> >
> > Sub ChangeZoom55()
> >
> > Application.ScreenUpdating = False
> > Dim Sh As Worksheet
> >
> > For Each Sh In Worksheets
> > Sh.Zoom = 55
> > Next
> >
> > Application.ScreenUpdating = True
> >
> > Sub Function
> >
> > There is the added frustration of hidden worksheets, so I am not sure
> > if I have to run a separate bit of code to un hide the hidden sheets,
> > if I do have to do this is there a way in which I can hide all the
> > sheets which were originally hidden but not the sheets that were
> > visible to start with.
> >
> > Any help much appreciated. Scott
> > = )

>
> Hi Scott,
>
> Helmut's right.
>
> I tried...
>
> Public Sub zoomAll()
> Dim Sht As Worksheet
> For Each Sht In ActiveWorkbook.Worksheets
> Sht.Activate
> ActiveWindow.Zoom = 50
> Next Sht
> End Sub
>
> which worked.
>
> Ken Johnson


 
Reply With Quote
 
Ken Johnson
Guest
Posts: n/a
 
      15th Jan 2007

spences10 wrote:
> Faaaantastic,
>
> thank you both
>
>
>
> Ken Johnson wrote:
> > spences10 wrote:
> > > Hi,
> > >
> > > I am trying to write a bit of code that changes the zoom property of a
> > > whole work book. Rather than use an array [as there are 40+ worksheets]
> > > I want to use 'For Each' statement like
> > >
> > > Sub ChangeZoom55()
> > >
> > > Application.ScreenUpdating = False
> > > Dim Sh As Worksheet
> > >
> > > For Each Sh In Worksheets
> > > Sh.Zoom = 55
> > > Next
> > >
> > > Application.ScreenUpdating = True
> > >
> > > Sub Function
> > >
> > > There is the added frustration of hidden worksheets, so I am not sure
> > > if I have to run a separate bit of code to un hide the hidden sheets,
> > > if I do have to do this is there a way in which I can hide all the
> > > sheets which were originally hidden but not the sheets that were
> > > visible to start with.
> > >
> > > Any help much appreciated. Scott
> > > = )

> >
> > Hi Scott,
> >
> > Helmut's right.
> >
> > I tried...
> >
> > Public Sub zoomAll()
> > Dim Sht As Worksheet
> > For Each Sht In ActiveWorkbook.Worksheets
> > Sht.Activate
> > ActiveWindow.Zoom = 50
> > Next Sht
> > End Sub
> >
> > which worked.
> >
> > Ken Johnson


You're welcome.
Thanks for the feedback

Ken Johnson

 
Reply With Quote
 
spences10
Guest
Posts: n/a
 
      16th Jan 2007
Hi,

there is one thing i have noticed though.

i have just checked the print preview of the document and it has
changed the scaling to like 10% ?

has this anything to do with it?, this is the only this that i have
changed =0

Ken Johnson wrote:
> spences10 wrote:
> > Faaaantastic,
> >
> > thank you both
> >
> >
> >
> > Ken Johnson wrote:
> > > spences10 wrote:
> > > > Hi,
> > > >
> > > > I am trying to write a bit of code that changes the zoom property of a
> > > > whole work book. Rather than use an array [as there are 40+ worksheets]
> > > > I want to use 'For Each' statement like
> > > >
> > > > Sub ChangeZoom55()
> > > >
> > > > Application.ScreenUpdating = False
> > > > Dim Sh As Worksheet
> > > >
> > > > For Each Sh In Worksheets
> > > > Sh.Zoom = 55
> > > > Next
> > > >
> > > > Application.ScreenUpdating = True
> > > >
> > > > Sub Function
> > > >
> > > > There is the added frustration of hidden worksheets, so I am not sure
> > > > if I have to run a separate bit of code to un hide the hidden sheets,
> > > > if I do have to do this is there a way in which I can hide all the
> > > > sheets which were originally hidden but not the sheets that were
> > > > visible to start with.
> > > >
> > > > Any help much appreciated. Scott
> > > > = )
> > >
> > > Hi Scott,
> > >
> > > Helmut's right.
> > >
> > > I tried...
> > >
> > > Public Sub zoomAll()
> > > Dim Sht As Worksheet
> > > For Each Sht In ActiveWorkbook.Worksheets
> > > Sht.Activate
> > > ActiveWindow.Zoom = 50
> > > Next Sht
> > > End Sub
> > >
> > > which worked.
> > >
> > > Ken Johnson

>
> You're welcome.
> Thanks for the feedback
>
> Ken Johnson


 
Reply With Quote
 
Ken Johnson
Guest
Posts: n/a
 
      16th Jan 2007

spences10 wrote:
> Hi,
>
> there is one thing i have noticed though.
>
> i have just checked the print preview of the document and it has
> changed the scaling to like 10% ?
>
> has this anything to do with it?, this is the only this that i have
> changed =0
>

Hi,

I just took one of my workbooks, checked each sheets appearance in
Print Preview, manually zoomed each sheet to 50%, checked Print Preview
appearances again, and there was no difference.
Then I rezoomed back to 100%, hid one of the sheets, ran the ZoomAll
macro, checked Print Preview appearances, and again there was no
change.

So I don't know what has caused your Print Previews to change.

Ken Johnson

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set the zoom property LetMeDoIt Microsoft Excel Programming 3 11th Sep 2007 05:04 AM
VBA error when accessing Zoom property =?Utf-8?B?VG9ueSBMb2dhbg==?= Microsoft Powerpoint 3 27th Nov 2006 04:31 AM
Changing Workbook Property =?Utf-8?B?UG9zc2VKb2hu?= Microsoft Excel Programming 1 12th Dec 2004 08:25 PM
Zoom property Umberto Giacobbi Microsoft Excel Programming 1 11th Aug 2004 07:29 AM
Zoom property error Luis Microsoft Excel Programming 1 17th Oct 2003 04:58 PM


Features
 

Advertising
 

Newsgroups
 


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