Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm not sure why you have a DoEvents call inside
the loop below but I didn't find it necessary. If your form to substitute the statusbar is merely to display something like "Wait, processing...", indeed only the one DoEvents just after showing the form is all you need. But if you want to inform user of progress, eg percentage done, you will probably need DoEvents each time you write the new update to the form within the loop. FWIW, changing the form's caption wouldn't need DoEvents. DoEvents is a relatively slow process, if you update the form with DoEvents in each loop you might double (or more) the overall length of your routine. However limiting to 100 updates, as in the example, would barely impact the overall time of a long loop. Be aware that DoEvents also enables user to trigger other processes within the loop, a candidate is attempting to close the form and hence the trap in the UserForm_QueryClose event in the example (though unlikely an issue with your single DoEvents). Regards, Peter T "tc69" wrote in message ... Bob Flanagan's Repaint suggestion worked but only partially. Often it would not finish displaying the message (about 20 characters). I tried adding a single DoEvents call right after my Show vbModeless call and it worked every time. Adding a single DoEvents call right after my Hide call also helps it clear itself before subsequent code executes as well. I'm not sure why you have a DoEvents call inside the loop below but I didn't find it necessary. Like I said, my Form simply displays a message in a Label control. It has no UserForm or Label Control Events implemented. Thanks! "Peter T" wrote: Typically would normally want to show the form as modal if it's merely to display progress, but perhaps modeless depending on what you are doing. Try something like this, limiting the number of times you update the form and in particular use DoEvents to a minimum. Sub test() Dim frm As UserForm1, lab As MSForms.Label Dim i As Long Dim nTo As Long, nPct As Long, nNextUpdate As Long nTo = 1000 Set frm = New UserForm1 frm.Show vbModeless Set lab = frm.Label1 frm.gbCodeRunning = True DoEvents For i = 1 To nTo Range("A1").Formula = "RAND()" If i = nNextUpdate Then nPct = nPct + 1 nNextUpdate = nPct * nTo / 100 lab.Caption = nPct - 1 & "% done " & i & " \ " & nTo & " " DoEvents If Not frm.gbCodeRunning Then Exit For End If End If Next frm.gbCodeRunning = False frm.Hide Unload frm ' not necessary with example as written but triggers QueryClose Set frm = Nothing End Sub ' in the form module Public gbCodeRunning As Boolean Private Sub UserForm_QueryClose(Cancel As Integer, _ CloseMode As Integer) If gbCodeRunning Then ' in case user clicks little x don't allow close form Cancel = True ' maybe allow user to cancel If MsgBox("Do you want to Cancel", vbYesNo) = vbYes _ Then gbCodeRunning = False End If End Sub Regards, Peter T "tc69" wrote in message ... I have a UserForm with a single Label Control that I do a .Show vbModeless on to display status messages. However, it only displays the the UserForm's Title Bar and Borders. The contents appear as solid white, unless I'm in Debug mode or I've done a MsgBox after I called .Show!?! Even then, as soon as I proceed with execution it'll go back to the blank white contents. If I choose not to .Hide it after I'm done with it, it'll show after my Macro has stopped!?! I've played with Application.ScreenUpdating and ..Interactive. Suggestions? Thanks! P.S. I don't want to use the Status Bar because it's not very noticeable and I still want Excel's normal Status messages to show. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
modeless userform problem | Excel Programming | |||
Modeless userform | New Users to Excel | |||
Modeless Userform problem | Excel Programming | |||
modeless userform | Excel Programming | |||
Modeless userform | Excel Programming |