2

I have a Sub that takes some time to process. I want an image that says "Please Wait" to appear on top of the form while processing and then disappear. I have tried this code but it is not working:

Private Sub UserForm_Initialize ()
Image1.visible=False
End Sub

Sub CommandButton1_Click ()
Image1.visible=True
'Here goes the process
Image1.visible=False
End Sub

Is that possible?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Gonzo
  • 53
  • 6
  • This kind of thing in VBA is messy at best and depends on what's going on in the process between those statements. I'd stick with `Application.StatusBar` – SierraOscar Nov 13 '15 at 14:28
  • It appears to work for me - I created a form with an image and button. I copied your code in to the form - replacing `'Here goes the process` with `Application.Wait Now + CDate("0:00:05")`. The image disappeared on the click event and reappeared five seconds later. Maybe edit your post with a `Wait` command to let people know there's meant to be code between the visible commands? – Darren Bartrup-Cook Nov 13 '15 at 14:36
  • you may find this [SO answer](http://stackoverflow.com/questions/5181164/progress-bar-in-vba-excel) very helpful... – Scott Holtzman Nov 13 '15 at 14:37
  • I've been looking around, and a Progress Bar is the go, but is still quite a development. I'm looking for something that can make a Visual Impact for the user without much coding. – Gonzo Nov 14 '15 at 17:51
  • Why would it not work? As to the best solution, this really depends on what you and your users expect as visualy suitable. What dont you like about your method? – Andrew Seabrook Nov 17 '15 at 12:22

1 Answers1

1

Add DoEvents to enable VBA to process the re-paint event

Sub CommandButton1_Click ()
  Image1.visible=True
  DoEvents
  'Here goes the process
  Image1.visible=False
End Sub
Ota Milink
  • 38
  • 1
  • 5