I have a VBA program to download attachments from a Mail Item.
I launch a macro (that is a 'sub' in a module), which does a 'Form.Show' to launch a userform. There is a button on the userform to kick off the download. The download sub is located in the module code, not the userform code.
Here's the code I'm using for the button:
Private Sub BTN_Download_Click()
Me.MousePointer = fmMousePointerHourGlass
Me.BTN_Download.Enabled = False
Utils.DownloadAttachments
Me.BTN_Download.Enabled = True
Me.MousePointer = fmMousePointerDefault
End Sub
I'm trying to present a well-behaved UI to the user: temporarily disabling the button and showing an hourglass when the operation is in action, and then re-enabling the button and restoring the default mouse pointer when complete.
What happens is the GUI becomes unresponsive, the button never appears to be disabled, and I don't see the hourglass pointer.
I tried moving the GUI code to the Module (MyForm.MousePointer=...). I tried creating two additional Sub, 'Busy' and 'UnBusy', and calling this directly from the Sub above - which works slightly better, but still there is a delay before the GUI looks 'Busy' to the开发者_运维技巧 user.
Is there a way of ensuring the GUI is updated?
Found the answer: 'DoEvents' - in fact the article below is talking about how 'DoEvents' is the older way of yielding control back to the GUI for refresh purposes in older versions of VB - seems to work well with VBA as well.
http://msdn.microsoft.com/en-us/library/aa719109%28VS.71%29.aspx
精彩评论