Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Showing/Hiding shapes

I am experiencing some odd behavior in some of my VBA and I'm hoping
someone can help me out. I have a rectangle on my sheet that I'm
trying to toggle on and off during a long VBA process to let the user
know something is happening in the background. My code is below:

Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make the updates are in progress
message appear
Application.ScreenUpdating = False
Call BuildSubj
Call BuildAud
Call BuildCert
Call BuildCat
Application.ScreenUpdating = True
Call DoIt("Rectangle 1", False) 'Make it disappear
End Sub

Sub DoIt(ShapeName, Vis)
ActiveSheet.Shapes(ShapeName).Visible = Vis
End Sub


The odd thing is that if I step through the BuildAll (using F8), the
rectangle appears and disappears like I would expect. If I just run
the BuildAll sub the rectangle never appears.

Any thoughts on this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Showing/Hiding shapes

Maybe try inserting the line

DoEvents

Right before Application.ScreenUpdating = False

I don't know why, but sometimes it makes a difference.

Hth

-John Coleman






On Apr 1, 7:16 pm, "Ferris" wrote:
I am experiencing some odd behavior in some of my VBA and I'm hoping
someone can help me out. I have a rectangle on my sheet that I'm
trying to toggle on and off during a long VBA process to let the user
know something is happening in the background. My code is below:

Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make the updates are in progress
message appear
Application.ScreenUpdating = False
Call BuildSubj
Call BuildAud
Call BuildCert
Call BuildCat
Application.ScreenUpdating = True
Call DoIt("Rectangle 1", False) 'Make it disappear
End Sub

Sub DoIt(ShapeName, Vis)
ActiveSheet.Shapes(ShapeName).Visible = Vis
End Sub

The odd thing is that if I step through the BuildAll (using F8), the
rectangle appears and disappears like I would expect. If I just run
the BuildAll sub the rectangle never appears.

Any thoughts on this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Showing/Hiding shapes

Thanks, but I'm still getting different results when I step-through
vs. run. Any other thoughts?


On Apr 1, 5:23 pm, "John Coleman" wrote:
Maybe try inserting the line

DoEvents

Right before Application.ScreenUpdating = False

I don't know why, but sometimes it makes a difference.

Hth

-John Coleman

On Apr 1, 7:16 pm, "Ferris" wrote:

I am experiencing some odd behavior in some of my VBA and I'm hoping
someone can help me out. I have a rectangle on my sheet that I'm
trying to toggle on and off during a long VBA process to let the user
know something is happening in the background. My code is below:


Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make the updates are in progress
message appear
Application.ScreenUpdating = False
Call BuildSubj
Call BuildAud
Call BuildCert
Call BuildCat
Application.ScreenUpdating = True
Call DoIt("Rectangle 1", False) 'Make it disappear
End Sub


Sub DoIt(ShapeName, Vis)
ActiveSheet.Shapes(ShapeName).Visible = Vis
End Sub


The odd thing is that if I step through the BuildAll (using F8), the
rectangle appears and disappears like I would expect. If I just run
the BuildAll sub the rectangle never appears.


Any thoughts on this?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Showing/Hiding shapes

Figured it out...If I add a 1 second delay after the command to show
the rectangle it works. Not sure why the delay is necessary, but it
does work.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Showing/Hiding shapes

On Apr 2, 11:33 am, "Ferris" wrote:
Figured it out...If I add a 1 second delay after the command to show
the rectangle it works. Not sure why the delay is necessary, but it
does work.


Truly strange.

If I try:

Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make visible
Application.ScreenUpdating = False

Call waste(3) 'a fill in for other subs

Application.ScreenUpdating = True
Call DoIt("Rectangle 1", False) 'Make it disappear
End Sub

Sub waste(s As Double)
Dim start As Double
start = Timer
Do While Timer < start + s
Loop
End Sub

Sub DoIt(ShapeName, Vis)
ActiveSheet.Shapes(ShapeName).Visible = Vis
End Sub

I am able to reproduce your problem, which seems to be some sort of
timing issue where Application.ScreenUpdating = False is executed
before the rectangle is visible.
For me, adding DoEvents after Call DoIt and before
Application.ScreenUpdating = False fixes the problem at once. On the
other hand, not even

Sub BuildAll()
Dim start As Double
Call DoIt("Rectangle 1", True) 'Make visible
start = Timer
Do While Timer < start + 5
Loop
Application.ScreenUpdating = False ...

works for me. Is this what you meant by a 1 second delay? (5 second
over-kill attempted in my case). On my machine, no mere delay seems to
work.

Interestingly, the following seems to work:

Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make visible
Application.ScreenUpdating = True
Application.ScreenUpdating = False

If this works it might be more portable across different versions of
Excel / machine configurations.

Hth

-John Coleman



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Showing/Hiding shapes

On Apr 2, 10:34 am, "John Coleman" wrote:
On Apr 2, 11:33 am, "Ferris" wrote:

Figured it out...If I add a 1 second delay after the command to show
the rectangle it works. Not sure why the delay is necessary, but it
does work.


Truly strange.

If I try:

Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make visible
Application.ScreenUpdating = False

Call waste(3) 'a fill in for other subs

Application.ScreenUpdating = True
Call DoIt("Rectangle 1", False) 'Make it disappear
End Sub

Sub waste(s As Double)
Dim start As Double
start = Timer
Do While Timer < start + s
Loop
End Sub

Sub DoIt(ShapeName, Vis)
ActiveSheet.Shapes(ShapeName).Visible = Vis
End Sub

I am able to reproduce your problem, which seems to be some sort of
timing issue where Application.ScreenUpdating = False is executed
before the rectangle is visible.
For me, adding DoEvents after Call DoIt and before
Application.ScreenUpdating = False fixes the problem at once. On the
other hand, not even

Sub BuildAll()
Dim start As Double
Call DoIt("Rectangle 1", True) 'Make visible
start = Timer
Do While Timer < start + 5
Loop
Application.ScreenUpdating = False ...

works for me. Is this what you meant by a 1 second delay? (5 second
over-kill attempted in my case). On my machine, no mere delay seems to
work.

Interestingly, the following seems to work:

Sub BuildAll()
Call DoIt("Rectangle 1", True) 'Make visible
Application.ScreenUpdating = True
Application.ScreenUpdating = False

If this works it might be more portable across different versions of
Excel / machine configurations.

Hth

-John Coleman


The DoEvents inserted before setting the ScreenUpdating = False didn't
do the trick for me. However, I've found my wait timer can cause an
Out of System Memory error if I'm running Real Player (streaming
content) at the same time if I select two ranges before I run it. For
example, the code below would throw the OOM every time during the 1
second pause until I removed the first A3 selection. I have 2Gb of RAM
and I was definitely not running out of memory... Weird stuff. I'll
have to see if O'Reilly has a VBA Annoyances book...

Range("A3").Select 'I have my view frozen and I want to be sure I'm in
the part of the sheet that will show the rectangle
Range("A2").Select 'Go to my header row
Call DoIt("Rectangle 1", True)

Sub DoIt(ShapeName, Vis)
ActiveSheet.Shapes(ShapeName).Visible = Vis
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime 'Gives time for the rectangle to show
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding/Showing Rows [email protected] Excel Programming 5 March 28th 07 08:00 PM
userforms showing and hiding Laurin[_11_] Excel Programming 4 December 20th 05 06:07 PM
hiding and showing graphs chrisrowe_cr Excel Worksheet Functions 0 September 2nd 05 11:22 AM
Showing and hiding columns BatMan Excel Programming 1 July 21st 04 06:11 PM
hiding showing columns using checkboxes ronda Excel Programming 1 June 8th 04 01:27 AM


All times are GMT +1. The time now is 04:42 AM.

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

About Us

"It's about Microsoft Excel"