MsgBox or form for display only

bkelly

Active Member
Joined
Jan 28, 2005
Messages
465
Is there any way to display a MsgBox or a user form with display attributes only? I want it to display but not stop my macros and not expect any user input. In a macro that does several things and takes a while to run, it will show progress. I am think of something on the order of:

Code:
sub work()

Pform.text = "task 1"
Pform.show
call task1()
pform.hide

Pform.text = "task 2"
Pform.show
call task2()
pform.hide

End Sub

The function work() would show the user form or message box and have no effect on the remainder of the macro. I asked about and tried a progress bar once, but it was barely noticable.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You have a few options, load a Shape and work with its text, use the Assistant and add your own messages, build a Modaless UserForm and work with its Labels and TextBoxes or use a timed to close Message Box.

Here is a Cloud Shape that I use and like:

Sub PleaseWait()
'Standard Module code, like: Module1!

With ActiveSheet.Shapes.AddShape(msoShapeCloudCallout, 200, 150, 150, 100)
.Name = "Wait a bit"
.TextFrame.Characters.Text = "Please Wait..." & Chr(10) & "I am working..." & Chr(10) & Chr(10) & "NOW!"
.TextFrame.HorizontalAlignment = xlHAlignCenter
.TextFrame.VerticalAlignment = xlVAlignCenter
End With

'Here is a timer call, but you can add your code here and when done,
'use the ActiveSheet.Shapes("Wait a bit").Delete code to remove it or
'change the text with the Text code above sample again.
'Or, just re-build the Cloud again!

Application.OnTime Now + 10 / 86400, "WaitOver"
End Sub

Sub WaitOver()
'Standard Module code, like: Module1!

On Error GoTo myEnd
ActiveSheet.Shapes("Wait a bit").Delete

myEnd:
End Sub
 
Upvote 0
Hi,
Thanks for the examples and I can see what the code does but I dont know how to add this to an existing macro.

I've got a macro Sub Line () that starts as shown below (there's plenty more of it !), how do I add your code into my code, sorry, but I'm definitely not an expert !

thanks for your help
Steve


Sub Lines()


Application.ScreenUpdating = False
'The following csv files need to be saved to the directory for the macro to work - Serial_Header, Serial_Lines and Serial_Payments

UserForm1.Show vbModeless

On Error GoTo errorhandler
'set up errorhandler label at bottom of macro, with messagebox

Sheets("Output_Header").Visible = True
Sheets("Output_Lines").Visible = True
Sheets("Output_Lines2").Visible = True
Sheets("Output_Payments").Visible = True

Sheets("Output_Lines").Select
Cells.Select
Selection.Copy
Sheets("Output_Lines2").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A2").Select

'Code adds duplicate last record for each serial number

Dim Rng As Range
 
Upvote 0
You stor the two Subs in a Standard Module, like Module1. Then in the sub you want the message to show when it runs, you Call the Sub "PleaseWait" before the slow code and when that code is finished you Call "WaitOver" like:

Sub xxx()
'some code here!

Call PleaseWait

'The slow code here!
'Slow code finished here!


Call WaitOver

End Sub
 
Upvote 0
Hi Joe,
Got it to work.....nice cloud !

Thanks again for your help, most appreciated.

cheers
Steve
 
Upvote 0
Hi there,

Not an answer to your question, but your code will run a lot quicker by removing all that unecessary selecting. So
Code:
Sheets("Output_Lines").Select 
Cells.Select 
Selection.Copy 
Sheets("Output_Lines2").Select 
Cells.Select 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
:=False, Transpose:=False 
Range("A2").Select
would become
Code:
Sheets("Output_Lines").Cells.Copy 
With Sheets("Output_Lines2")
.Cells.PasteSpecial xlPasteValues
.Range("A2").Select 
End With
 
Upvote 0
Nice one, thanks for the revised code.

As you can see, my vba knowledge is very bit limited, I tend to record the code then bolt on a few other bits so I appreciate your help in improving the effeciency.

Cheers
Steve
 
Upvote 0

Forum statistics

Threads
1,225,213
Messages
6,183,621
Members
453,176
Latest member
alphonsa12

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top