PC Review


Reply
Thread Tools Rate Thread

Change view without activating sheet?

 
 
michael.beckinsale
Guest
Posts: n/a
 
      13th Jun 2008
Hi All,

Below is a code snippet from a routine that loops through each sheet
in a workbook. The routine copies / pastes ranges into powerpoint so l
need to ensure the sheet is in normal view to avoid pages numbers etc
being passed to PP

Sht1.Activate
If ActiveWindow.View = xlPageBreakPreview Then
ShtView = "Yes"
ActiveWindow.View = xlNormalView
End If

How can l achieve this without using Sht1.Activate?

I want to avoid the 'flashing' caused by the Sht1.Activate. If l use
Application.Screenupdating = False the data is not passed to PP

Regards

Michael
 
Reply With Quote
 
 
 
 
IanC
Guest
Posts: n/a
 
      13th Jun 2008
Just a guess...

If Sht1.View = xlPageBreakPreview Then
ShtView = "Yes"
ActiveWindow.View = xlNormalView
End If

--
Ian
--
"michael.beckinsale" <(E-Mail Removed)> wrote in message
news:5243fd77-09d5-4513-a2e2-(E-Mail Removed)...
> Hi All,
>
> Below is a code snippet from a routine that loops through each sheet
> in a workbook. The routine copies / pastes ranges into powerpoint so l
> need to ensure the sheet is in normal view to avoid pages numbers etc
> being passed to PP
>
> Sht1.Activate
> If ActiveWindow.View = xlPageBreakPreview Then
> ShtView = "Yes"
> ActiveWindow.View = xlNormalView
> End If
>
> How can l achieve this without using Sht1.Activate?
>
> I want to avoid the 'flashing' caused by the Sht1.Activate. If l use
> Application.Screenupdating = False the data is not passed to PP
>
> Regards
>
> Michael



 
Reply With Quote
 
michael.beckinsale
Guest
Posts: n/a
 
      13th Jun 2008
Hi IanC,

Sorry you guessed wrong!

Already tried that and l suspect it fails because 'View' is not a
property of a Sheet,

Michael

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      13th Jun 2008
Doing things with the Windows object is one of the few occasions you do need
to use select or activate. Though in this case you could do all in one go,
select all sheets, change the view to xlNormalView (if the activesheet was
already xlNormalView you'd need to change all to xlPageBreakPreview first)

But why not loop through your sheets first with screenupdating disabled and
set each view as required (only if necessary). Perhaps store any changed
settings in an array to be reset when done.

Enable screenupdating and do your stuff. IOW two loops, or perhaps three if
you want to reset.

Regards,
Peter T


"michael.beckinsale" <(E-Mail Removed)> wrote in message
news:5243fd77-09d5-4513-a2e2-(E-Mail Removed)...
> Hi All,
>
> Below is a code snippet from a routine that loops through each sheet
> in a workbook. The routine copies / pastes ranges into powerpoint so l
> need to ensure the sheet is in normal view to avoid pages numbers etc
> being passed to PP
>
> Sht1.Activate
> If ActiveWindow.View = xlPageBreakPreview Then
> ShtView = "Yes"
> ActiveWindow.View = xlNormalView
> End If
>
> How can l achieve this without using Sht1.Activate?
>
> I want to avoid the 'flashing' caused by the Sht1.Activate. If l use
> Application.Screenupdating = False the data is not passed to PP
>
> Regards
>
> Michael



 
Reply With Quote
 
michael.beckinsale
Guest
Posts: n/a
 
      13th Jun 2008
Hi Peter,

I was afraid that was the response l was going to get.

I have taken your suggestion on board and created loops to set the
worksheet views, store in an array, and then restore views
accordingly.

It seems a disproportionate amount of work to simply set the view but
l suppose thats Microsoft / VBA !

Thanks very much for your kind help over the past couple of days.

Regards

Michael

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      13th Jun 2008
In the big scheme of things it's not that much work -

Sub test()
Dim i As Long
Dim shtOrig As Object

ReDim bArr(1 To Worksheets.Count) As Boolean
Set shtOrig = ActiveSheet

Application.ScreenUpdating = False
For i = 1 To Worksheets.Count
Worksheets(i).Select
If ActiveWindow.View = xlPageBreakPreview Then
ActiveWindow.View = xlNormalView
bArr(i) = True
End If
Next
shtOrig.Select
Application.ScreenUpdating = True


' Do stuff

Stop ' have a look

Application.ScreenUpdating = False
For i = 1 To Worksheets.Count
If bArr(i) = True Then
Worksheets(i).Select
ActiveWindow.View = xlPageBreakPreview
End If
Next
shtOrig.Select
Application.ScreenUpdating = True

End Sub

Regards,
Peter T

"michael.beckinsale" <(E-Mail Removed)> wrote in message
news:c03be41c-5d09-45fe-988b-(E-Mail Removed)...
> Hi Peter,
>
> I was afraid that was the response l was going to get.
>
> I have taken your suggestion on board and created loops to set the
> worksheet views, store in an array, and then restore views
> accordingly.
>
> It seems a disproportionate amount of work to simply set the view but
> l suppose thats Microsoft / VBA !
>
> Thanks very much for your kind help over the past couple of days.
>
> Regards
>
> Michael
>



 
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
change custom view when leaving a sheet Graham Y Microsoft Excel Programming 12 20th May 2009 04:00 PM
Change view without activating sheet? - Repost michael.beckinsale Microsoft Excel Programming 1 13th Jun 2008 01:03 PM
[help]how to change embedded excel sheet 's view range? BlueCoast Microsoft Excel Programming 0 9th Apr 2008 05:48 AM
autorun upon activating a sheet cdde Microsoft Excel Programming 0 10th Nov 2004 11:43 PM
autorun upon activating a sheet cdde Microsoft Excel Programming 1 10th Nov 2004 07:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:16 AM.