Deprecated: Creation of dynamic property CF\WordPress\DataStore::$logger is deprecated in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php on line 23

Deprecated: Creation of dynamic property CF\WordPress\Proxy::$pluginAPI is deprecated in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/Proxy.php on line 31

Deprecated: file_get_contents(): Passing null to parameter #2 ($use_include_path) of type bool is deprecated in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/codelights-shortcodes-and-widgets/codelights.php on line 20

Warning: session_start(): Session cannot be started after headers have already been sent in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/automatic-video-posts/vendor/ternstyle/wordpress/src/class/wordpress.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Deprecated: Creation of dynamic property ternplugin\youtube_video::$post is deprecated in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/automatic-video-posts/vendor/ternstyle/plugin/src/class/youtube_video.php on line 64

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home1/cassanoc/public_html/bonbonsguide.com/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":5677,"date":"2023-05-04T12:10:13","date_gmt":"2023-05-04T19:10:13","guid":{"rendered":"https:\/\/bonbonsguide.com\/wp\/?p=5677"},"modified":"2023-05-04T12:35:51","modified_gmt":"2023-05-04T19:35:51","slug":"how-to-make-excel-wait-or-pause","status":"publish","type":"post","link":"https:\/\/bonbonsguide.com\/wp\/blog\/2023\/05\/how-to-make-excel-wait-or-pause\/","title":{"rendered":"How to Make Excel Wait or Pause in a VBA Macro"},"content":{"rendered":"\n

When running macros, I have often found the need for an Excel wait or pause, mainly so that other things can happen. DoEvents surely helps for waiting for things to happen within Excel, but sometimes you need to wait for processes to start or finish outside of Excel before moving onto other steps in VBA.<\/p>\n\n\n\n

Why Wait?<\/h2>\n\n\n\n

I am a big fan of automating processes, especially with VBA in Excel. For example, I update and save a spreadsheet to SharePoint that a Power BI model is using. I have a Power Automate process set up that automatically refreshes the Power BI model whenever this particular spreadsheet is updated. The challenge is that Power BI temporary locks the workbook as it reads it, so if I am updating a few times in a short amount of time, Excel needs to wait until the SharePoint file is unlocked.<\/p>\n\n\n\n

Also, I have another process where I call a Python script and once that is done, I continue on with VBA code to process the workbook Python outputs. I need Excel to wait while the Python code runs. Side note: let me know if you would like me to write more about these other automated processes. <\/p>\n\n\n\n

The Solution<\/h2>\n\n\n\n

Good news – making Excel wait is very easy! Here is the simple code:<\/p>\n\n\n\n

Application.Wait (Now + TimeValue(\"0:00:50\"))<\/code><\/pre>\n\n\n\n

This will have Excel wait for 50 seconds since the time is represented as (H:MM:SS). You can adjust as needed.<\/p>\n\n\n\n

Bonus<\/h2>\n\n\n\n

In my code, I don’t need it to wait every time – only when it runs into an issue saving the workbook on SharePoint. Here is how I have set my code using an error handler in my VBA macro. <\/p>\n\n\n\n

On Error GoTo waitforupdate\n\nlsc.SaveAs Filename:= _\n        \"https:\/\/sharepoint.com\/sites\/Reporting\/Milestones\/Status.xlsx\" _\n        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False\n        \nlsc.Close\nExit Sub\n\nwaitforupdate:\nApplication.Wait (Now + TimeValue(\"0:00:50\"))\nResume Next\n<\/code><\/pre>\n\n\n\n

I hope this helps you! Please comment or reach out if you would like to see other topics covered. I truly enjoy writing about Excel tips and tricks, especially VBA and automation!<\/p>\n\n\n\n

Addressed in this post (to help others find this):<\/p>\n\n\n\n

    \n
  • How to pause Excel<\/li>\n\n\n\n
  • How to make Excel pause<\/li>\n\n\n\n
  • Make VBA pause<\/li>\n\n\n\n
  • Make VBA wait<\/li>\n\n\n\n
  • Make Excel wait<\/li>\n\n\n\n
  • VBA code wait, VBA macro wait<\/li>\n\n\n\n
  • VBA code pause, VBA macro pause<\/li>\n\n\n\n
  • VBA wait for another application<\/li>\n<\/ul>\n\n\n\n

    <\/p>\n","protected":false},"excerpt":{"rendered":"

    When running macros, I have often found the need for an Excel wait or pause, mainly so that other things can happen. DoEvents surely helps for waiting for things to happen within Excel, but sometimes you need to wait for processes to start or finish outside of Excel before moving onto other steps in VBA. […]<\/p>\n","protected":false},"author":1,"featured_media":137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[226,21,30],"tags":[25,20,285,24,283],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/bonbonsguide.com\/wp\/wp-content\/uploads\/2016\/09\/codeexecutionhasbeeninterrupted-1.jpg?fit=380%2C214&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7QB1z-1tz","_links":{"self":[{"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/posts\/5677"}],"collection":[{"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/comments?post=5677"}],"version-history":[{"count":9,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/posts\/5677\/revisions"}],"predecessor-version":[{"id":5690,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/posts\/5677\/revisions\/5690"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/media\/137"}],"wp:attachment":[{"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/media?parent=5677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/categories?post=5677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bonbonsguide.com\/wp\/wp-json\/wp\/v2\/tags?post=5677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}