cause a delay in script

momukhtar

New Member
Joined
Jul 3, 2007
Messages
11
I am using the workbook.open method in read only mode and then converts all the chart objects in the excel file into png images. The problem is that it takes a while for excel to produce charts correctly and the script executes as soon as the file is opened, because of this the images are not the same as the actual charts and the curves are not proper.

What is the way to insert a delay in the script so that the charts are produced correctly and then they are exported into images.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
Hello momukhtar,
There are in fact ways to delay the execution of code in mid stream but it's probably easier
and more reliable to break this code up into two separate routines.
Look at your current Wb_Open routine and determine the point at which you want it to pause.
Then take everything you want it to do after the pause and write that as a separate sub in
a standard module. (Say you named that "WbOpenContinued")
Then in the Wb_Open, have it perform everything up to & including your "pause" point and
end that sub with:
Application.OnTime Now + TimeValue("00:00:05"), "WbOpenContinued"
just before the End Sub line.

This will allow the first part to execute (as a stand alone routine), allow the sheet(s)/chart(s) to
calculate/update and then 5 seconds later the second routine (which is actually the second
half of the original operation) will be called as its own sepatare routine.

Know what I mean?

(Obviously, you can change the TimeValue to whatever you want, but I find anything under
2 seconds to be rather unreliable due to the scan cycles of different computers, etc.)

Hope it helps.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,833
Messages
5,833,893
Members
430,241
Latest member
Matty Se

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
Top