Display/Hide image while code is working

Vintage79

Board Regular
Joined
May 29, 2007
Messages
185
Office Version
  1. 2019
Platform
  1. Windows
Hello all,

I would like to display a 'please wait' image while my code is working. So, Sheet1 is for the user to press a button and activate the code. On the hidden Sheet2 I have an image that I have named as 'Image01'.

I'm thinking that I could use something like this:

When button is pressed to run code:

Call Image01 from Sheet2 and display it on Sheet1
Application.ScreenUpdating = False
Code then runs here
Application.ScreenUpdating = True
Hide Image01


Is this possible? Thanks for any advice!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this when there is only one picture on sheet2
VBA Code:
Sub ImageShow()
    With ActiveWorkbook.Sheets("Sheet2")
        .Visible = 1
        .Activate
    End With
    Application.ScreenUpdating = 0
End Sub

Sub ImageHide()
    ActiveWorkbook.Sheets("Sheet2").Visible = xlSheetHidden
    Application.ScreenUpdating = 1
    MsgBox "The code has worked!"
End Sub

Sub wait()
Call ImageShow
YOUR CODE
Call ImageHide
End Sub
 
Upvote 0
Ok, I tried LazyBug's code:
VBA Code:
Sub ImageShow()
    With ActiveWorkbook.Sheets("Sheet2")
        .Visible = 1
        .Activate
    End With
    Application.ScreenUpdating = 0
End Sub

Sub ImageHide()
    ActiveWorkbook.Sheets("Sheet2").Visible = xlSheetHidden
    Application.ScreenUpdating = 1
    MsgBox "The code has worked!"
End Sub

Sub Wait()
Call ImageShow
Application.Wait (Now + TimeValue("0:00:03"))
Call ImageHide
End Sub

Again, this worked on step-through, but when I 'run sub' I just get the 3 second delay and the msg box at the end. There must be some issue with my software?
 
Upvote 0
Comment or delete the line
VBA Code:
Application.Wait (Now + TimeValue("0:00:03"))
and put it in its place your code that should work while the picture on the sheet2 is displayed between call lines.
 
Upvote 0
Application.Wait is problematic as it holds code execution ... I would try a timed loop instead

VBA Code:
Sub Test()
    Sheets("Sheet1").Shapes("Image01").Visible = True
    Call Wait(5)
    Sheets("Sheet1").Shapes("Image01").Visible = False
    Application.ScreenUpdating = Application.ScreenUpdating
End Sub

Sub Wait(ByVal Secs As Single)
    Dim t As Single
    t = Timer
    Do
        DoEvents
    Loop Until Timer - t >= Secs
End Sub

Edit : This assumes the image is on Sheet1
 
Upvote 0
Ok, I found a possible workaround:

VBA Code:
    Sheet2.Shapes("Image01").Copy
    Range("A1").Activate
    ActiveSheet.Paste
    Application.Wait (Now + TimeValue("0:00:03"))
    ActiveSheet.Shapes("Image01").Delete

This runs from Sheet 1, and works perfectly. For some reason I could not paste straight into A1 on Sheet1, I had to write 3 lines, where usually I would just write:

VBA Code:
    Sheet2.Shapes("Image01").Copy Range("A1")

But thank you to everyone for the ideas & suggestions. I might try the timed loop too!
 
Upvote 0
Solution
This is exactly what that was designed to do. It takes an image from your workbook
Thank you for this suggestion. Unfortuantely this solution wouldn't work for me, as it would require any user of the code, to first copy the image to a specific location on their machine. I was hoping there might be a way to do this by already having the image in the workbook.
 
Upvote 0

Forum statistics

Threads
1,215,147
Messages
6,123,296
Members
449,095
Latest member
Chestertim

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