Popup required

G

Guest

For a longish macro (made up of a few smaller macros), what is a simple way
of displaying a message box saying "operation in progress, etc", and then
when the macro has finished, another message box with an OK button saying
"operation completed"?
 
G

Gordon Bentley-Mix

For the first requirement, just create a UserForm with the appropriate
message on it (I use one called 'frmWaitMsg' that just says "Building
Document - Please wait...") and make sure its ShowModal property is set to
false. This will allow code to run while the UserForm is displayed. Show the
form at the start of your code and hide it again at the end. Note that you
might have to repaint the UserForm to get it to display properly. The code I
use looks like this:

Private Sub CreateNewDocument
Dim myWaitMsg As frmWaitMsg
Set myWaitMsg = New frmWaitMsg
With myWaitMsg
.Show
.Repaint
End With
' ---
' Run the code to build the document
' ---
myWaitMsg.Hide
Unload myWaitMsg
Set myWaitMsg = Nothing
End Sub

For the second requirement, it should be as simple as adding the line:

MsgBox "Operation Complete"

just before the End Sub, although you could tart up the message box a bit by
explicitly setting the VbMsgBoxStyle property to vbOKOnly (which is the
default value) and setting the Title property to something appropriate.
 
G

Guest

Gordon Bentley-Mix said:
For the first requirement, just create a UserForm with the appropriate
...

Thanks.

I somehow thought that both of the messages would be as simple as the second
one. And even though this macro is for my personal use, I implemented your
suggestions and it works.

Regards,

Sergey
 
G

Gordon Bentley-Mix

Unfortunately, Word VBA doesn't provide a "buttonless" non-modal message box
that can be invoked and dismissed programmatically. Any message boxes you
display using the MsgBox function will always be modal (which will halt code
execution) and always require user intervention to dismiss (which means at
least one button and an associated user action). The only choice you have is
to build your own. Glad my method appears to be working for you.
 
G

Guest

Gordon Bentley-Mix said:
Unfortunately, Word VBA doesn't provide a "buttonless" non-modal message
box that can be invoked and dismissed programmatically. Any message boxes
you display using the MsgBox function will always be modal (which will
halt code execution) and always require user intervention to dismiss
(which means at least one button and an associated user action). The only
choice you have is to build your own. Glad my method appears to be working
for you.

Your method works, not appears to be working.

Cheers,

Sergey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top