Consulting

Results 1 to 3 of 3

Thread: How to use DoEvents in VBA

  1. #1
    VBAX Newbie
    Joined
    Aug 2006
    Posts
    2
    Location

    Question How to use DoEvents in VBA

    Hi,

    I am running some code which takes sometime to complete, and I wish to display a message to the user in the form of a changing caption in a label on a userform. I only have one form open, but using DoEvents in the way I have used it, does not cause the caption to change. Basically, a series of proceedures run, and at the end of each one, I have used DoEvents to update the caption. Where have I gone wrong? Here is an example of the code:-

    [VBA]myform = DoEvents

    If myform = 1 Then
    Application.ScreenUpdating = True
    With frmSelectFile
    .lblprocessActual.ForeColor = vbBlack
    .lblprocessActual.Caption = "Done"
    .lblProcessFiled.ForeColor = vbRed
    .lblProcessFiled.Caption = ">> Processing FILED data..."
    End With
    Application.ScreenUpdating = False
    End If[/VBA]

    many thanks if you can help

    Tim

  2. #2
    MS Excel MVP VBAX Tutor
    Joined
    Mar 2005
    Posts
    246
    Location
    You just use DoEvents as a standalone command. I don't think it's what you want. Try .Repainting the form after updating it. Screen updating wouldn't affect the form either, it is concerned with updating the appearance of the workbooks and sheets in Excel.
    [vba]
    With frmSelectFile
    .lblprocessActual.ForeColor = vbBlack
    .lblprocessActual.Caption = "Done"
    .lblProcessFiled.ForeColor = vbRed
    .lblProcessFiled.Caption = ">> Processing FILED data..."
    .Repaint
    End With
    [/vba]
    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com
    _______

  3. #3
    VBAX Newbie
    Joined
    Aug 2006
    Posts
    2
    Location

    Works fine

    Many thanks Jon. The solution worked fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •