VBA Run Loop while Refresh All Running

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
Hello, I have code that refreshes the workbook but I would like a loop to run during this time then when the refresh is complete close userform.
Push Button
Button Opens userform that runs a loop GIF.
Refresh All
When Refresh Complete close userform.

Any Ideas? Here is my current code. but the issue is the GIF will run but not until I close the userform then it refreshes the workbook.
Code:
Sub Refresh()
   
With frmStatus
  .Top = Int(((Application.Height / 2) + Application.Top) - (.Height / 2))
  .Left = Int(((Application.Width / 2) + Application.Left) - (.Width / 2))
  Load frmStatus
  .Show vbModeless
  
   'DoEvents
   'Application.Run "RefreshData"
   Unload frmStatus
   
End With
End Sub


Sub RefreshData()

ActiveWorkbook.RefreshAll
Unload frmStatus

End Sub

'loop

Private Sub UserForm_Activate()

    Running = True
    Call Animation

End Sub

Private Sub Animation()


Dim x               As Integer
Dim y               As Integer
Dim MyTimer         As Double

   DoEvents
   x = 1
   y = 1
   MyTimer = Timer
   Do
       On Error Resume Next
       frmStatus.Image3.Picture = LoadPicture _
               ("C:\Users\lawryad\Pictures\GEAR\GIF\a6632905e0-gif-im\" & x & ".Gif")
       On Error GoTo 0
       Do
       Loop While Timer - MyTimer < 0.05
       If x = 8 Then
           x = 1
           Else
           x = x + 1
       End If
       If y = 11 Then
           y = 1
           Else
           y = y + 1
       End If
       MyTimer = Timer
       DoEvents
   Loop While Running



End Sub
Private Sub UserForm_Initialize()

    Application.WindowState = xlMaximized

End Sub
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,827
Messages
6,121,803
Members
449,048
Latest member
greyangel23

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