Good day!
I'm attempting to have a userform display a message while my macro runs however, the userform is showing up as blank when I run the macro. I'm a bit baffled at this? Appreciate any comments or help!
Cheers!
Good day!
I'm attempting to have a userform display a message while my macro runs however, the userform is showing up as blank when I run the macro. I'm a bit baffled at this? Appreciate any comments or help!
Cheers!
tóg(a'í) go réidh é!
Cheers!
You need to show the form and run your macro from within there, close the form when the macro ends.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Thanks for the prompt reply!
I think I understand what you are getting at.
So am I basically copying the code from my module and putting it into the userform? Will this work still if I'm calling the macro from a button and the user needs to input data?
tóg(a'í) go réidh é!
Cheers!
NO, you can leave the code in your module, but just call the sub from the form, say in the Userform_Activate event.
If you have a button to launch it, the button would launch another macro to show the userform.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Thanks for the direction! I'll play around with it!
Cheers!
tóg(a'í) go réidh é!
Cheers!
You can also show the form modelessly and then repaint it immediately before your remaining code is called.
Be as you wish to seem
Thanks for the suggestion Aflatoon.
I had the mode turned to false and was still have issues with the form showing blank. I found some additional bits of code out on the web but was having trouble getting them to work.
I think that in the end, my WB will end up being a little less fancy than i was planning as I'm still encountering some issues.
tóg(a'í) go réidh é!
Cheers!
Did you repaint it after showing? Or use DoEvents?
Be as you wish to seem
I tried inserting the form at the beginning of the macro I wanted it to pop during and unsuccessfully tried repainting it. Didn't work for me...
I did not use a DoEvent.
tóg(a'í) go réidh é!
Cheers!
Either of these should work:
[vba]
Dim myForm as userform1
set myForm = New Userform1
myform.show false
myform.repaint
' the rest of your code would go here
[/vba]
or:[vba]
Dim myForm as userform1
set myForm = New Userform1
myform.show false
DoEvents
' the rest of your code would go here
[/vba]
Be as you wish to seem
Aflatoon,
Both of your solutions work perfectly, thank you mate!
I can't get my the form to disappear after the macro runs. I tried unloading the form but it's not working. Any thoughts?
Cheers!
tóg(a'í) go réidh é!
Cheers!
At the end of the routine, it would just be:
[vba]Set myForm = Nothing[/vba]
Be as you wish to seem
Hmmm.... using that bit of code doesn't seem to be having any affect. The form is stubbornly not disappearing.
I'm using the DoEvents syntax you provided. I'm uncertain if that would make a difference?
tóg(a'í) go réidh é!
Cheers!
My apologies - glaring omission there. It should be:
[vba]
unload myForm
Set myForm = Nothing[/vba]
Be as you wish to seem
Works like a charm!
Cheers!
tóg(a'í) go réidh é!
Cheers!
Good day Alfatoon,
I seem to have encountered one more error with the userform code you've provided.
The userform displays while a macro runs and works great. The macro is prompted from a user selecting a button. When the user cancels out of the button to prevent the macro from running I get an "Object variable or With block not set". When I debug its pointing me to the code [vba]Unload myForm[/vba]
Any thoughts on this mate?
Many thanks!
tóg(a'í) go réidh é!
Cheers!
I think I fixed it, not sure if its proper though...
Here's my solution:
[VBA]
On Error Resume Next
Unload myForm[/VBA]
tóg(a'í) go réidh é!
Cheers!
You could name the userform explicitly rather than refering to a variable. [vba]Unload Userform1[/vba] or you could assign the variable myForm to Userform1 at the beginning of the routine, before the user has an opportunity to cancel.