VBA wait for picture change

zilch42

New Member
Joined
Apr 14, 2016
Messages
1
Hi there. I have a picture that I am changing based on the result of a formula. I have a hidden sheet with all of the possible pictures sitting in cells and this part is working fine. But all of the pictures are different sizes so I am trying to run a macro to rescale the picture after the formula has changed. The pictures are quite large (basically cropped screenshots) so they are taking half a second to load and the resize macro is running before the picture has changed and therefore using the size dimensions of the old picture.

My current code is below. It's basically checking whether L13 has changed (which is part of the formula for changing the picture) and then selects the pic and resizes it.

Code:
Private Sub Worksheet_Calculate()


VConc = ActiveSheet.Range("L13").Value


If VConc <> VPreConc Then
    
    ActiveSheet.Shapes.Range(Array("VinPic1")).Select
    Selection.ShapeRange.ScaleWidth 1, msoTrue
    Selection.ShapeRange.ScaleHeight 1, msoTrue


End If


VPreConc = ActiveSheet.Range("L13").Value


End Sub

I have tried the following and it seems to work sometimes and not others. And 3 seconds is way longer than the picture normally takes to change
Code:
    Application.Wait (Now + TimeValue("00:00:03"))
    DoEvents

I've also tried playing with Application.CalculationState and DoEvents to no avail.

Any idea how I can make sure the new picture is in there before running the resize?

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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