View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
tc69 tc69 is offline
external usenet poster
 
Posts: 19
Default Modeless Userform Not Displaying

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.