Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Problem with hide/show for userform where showmodal is set to true

I have a userform named FunctionButtons with showmodal set to true that is
displayed automatically by the workbook_open event procedure with the following
code:

VBA.UserForms.Add(FunctionButtons.Name).Show

The form is displayed on the first and only worksheet in the workbook when the
workbook is opened.

One of the macros (accessed by clicking one of the button on the FunctionButtons
form) adds a new worksheet and activates the new worksheet.

I don't want the FunctionButtons form displayed on the second worksheet so I
added the following code to the first worksheet.

Private Sub Worksheet_Activate()
FunctionButtons.Show
End Sub

Private Sub Worksheet_Deactivate()
FunctionButtons.Hide
End Sub

I know these routines are executed at the right times from placing breakpoints
in them.

Sometimes with the second worksheet is added and displayed the FunctionButtons
form is still displayed. When this happens going back to the first worksheet
causes a second copy of the form to be displayed. Getting the second copy of
the form only happens once regardless of the number of times you switch back and
forth between the first and second worksheets. If it happens it is always the
first time switching back to the first worksheet.

Other times everything appears to work correctly - no form on the second
worksheet and no second copy of the form on the first worksheet.

One other thing I found - when the hide/show stuff works the following line of
code does not work.

AppActivate ActiveWorkbook.Windows(1).Caption

When the hide/show stuff does not work the same lime of code works fine.

The error generated when the line of code doesn't work is "Invalid procedure
call or argument".

Any ideas as to what is going on? I've spent most of the day trying to figure
this out without an success.

Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Problem with hide/show for userform where showmodal is set totrue

I changed the code in the workbook_open event procedure from

VBA.UserForms.Add(FunctionButtons.Name).Show

to

FunctionButtons.Show

and the problem is gone.

So what's the difference between the 2 ways of showing a form?

Mike Clemens wrote:
I have a userform named FunctionButtons with showmodal set to true that
is displayed automatically by the workbook_open event procedure with the
following code:

VBA.UserForms.Add(FunctionButtons.Name).Show

The form is displayed on the first and only worksheet in the workbook
when the workbook is opened.

One of the macros (accessed by clicking one of the button on the
FunctionButtons form) adds a new worksheet and activates the new
worksheet.

I don't want the FunctionButtons form displayed on the second worksheet
so I added the following code to the first worksheet.

Private Sub Worksheet_Activate()
FunctionButtons.Show
End Sub

Private Sub Worksheet_Deactivate()
FunctionButtons.Hide
End Sub

I know these routines are executed at the right times from placing
breakpoints in them.

Sometimes with the second worksheet is added and displayed the
FunctionButtons form is still displayed. When this happens going back
to the first worksheet causes a second copy of the form to be
displayed. Getting the second copy of the form only happens once
regardless of the number of times you switch back and forth between the
first and second worksheets. If it happens it is always the first time
switching back to the first worksheet.

Other times everything appears to work correctly - no form on the second
worksheet and no second copy of the form on the first worksheet.

One other thing I found - when the hide/show stuff works the following
line of code does not work.

AppActivate ActiveWorkbook.Windows(1).Caption

When the hide/show stuff does not work the same lime of code works fine.

The error generated when the line of code doesn't work is "Invalid
procedure call or argument".

Any ideas as to what is going on? I've spent most of the day trying to
figure this out without an success.

Thanks for your help.

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
ShowModal, Hide Form, Print Preview Office 2007 Gil[_5_] Excel Programming 2 August 4th 08 09:53 PM
UserForm ShowModal Problem RyanH Excel Programming 0 May 9th 08 02:14 AM
ShowModal = False but Textbox does not show on userform ExcelMonkey Excel Programming 1 March 20th 07 08:34 PM
Userform show / hide problem brookly Excel Programming 6 March 18th 06 09:48 PM
UserForm - ShowModal Error Brian Hribek[_3_] Excel Programming 2 October 31st 04 04:11 PM


All times are GMT +1. The time now is 08:57 AM.

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

About Us

"It's about Microsoft Excel"