Reputation: 569
I have a progress using a userform. I show the userform when a worksheet button is clicked. The button calls startProgressIndicator()
Sub startProgressIndicator()
UserForm1.Show
End Sub
I have this as my userform code:
Private Sub UserForm_Activate()
Call myCode
End Sub
I then want to hide the progress bar and ask for user input. This occurs in myCode
. I inlcude UserForm1.Hide
in beginning of myCode
.
After getting the user input, I want to show the progress indicator again.
I try UserForm1.Show
, however, this just calls myCode
all over again. I just want the same userform to be visible again.
I tried using UserForm1.Visible = False
, but then I get this error
Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic
Upvotes: 1
Views: 1880
Reputation: 2438
Short answer is to rewrite myCode
to not include .Hide
. Break myCode
into logical chunks.
However, you should separate the logic from the display (see Rubberduck UserForm1.Show (*)). By doing so - you would only call .Hide
from the form when you want to (e.g. on the 'Close' button click).
@ChrisNeilsen suggested using _Initialize
and this will solve the immediate problem but will not set you up for better programming practices in the future. lso, if you decide to modify myCode
you may get bugs that are harder to identify.
@ChrisNeilsen: Use 'UserForm_Initialize' rather than 'UserForm_Activate'
(*) No disclaimer required, I am in no way affiliated with Rubberduck, but it does make good reading!
Upvotes: 1