VBA set time delay before running the next macro line

Raychin

New Member
Joined
Apr 7, 2022
Messages
25
Office Version
  1. 2013
Platform
  1. Windows
Hello! I have an issue setting up a time delay for my macro, so a file can be opened trough .odc file.
So i need to give time to the .odc file to executes and open the excel file with the table inside, and afterwards all cells to be selected for extraction or processing.
The part of the code where i want to put a delay/buy time is just before the command for Cells selection. I thing i need a simple loop, but i'm not familiar with loops. Maybe Wait function is just pausing the macro run and that's why i see first all cells selection and afterwards the .odc file execution.
Can you help me with adding time to open the .odc file properly please?

VBA Code:
Sub Open_Any_File()

    VBA.Shell "explorer.exe C:\Raychi files\TSO Metered Data\EnergoPro_Meterd_Data.odc"
    
    Application.Wait (Now + TimeValue("0:00:10"))

    ActiveSheet.Cells.Select
    

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Please Try this
VBA Code:
Sub Open_Any_File()
  VBA.Shell "explorer.exe C:\Raychi files\TSO Metered Data\EnergoPro_Meterd_Data.odc"
  Application.OnTime Now() + TimeValue("00:00:10"), "OkGo", schedule:=True
  
End Sub


Sub OkGo()
  ActiveSheet.Cells.Select
End Sub
 
Upvote 0
Solution
Please Try this
VBA Code:
Sub Open_Any_File()
  VBA.Shell "explorer.exe C:\Raychi files\TSO Metered Data\EnergoPro_Meterd_Data.odc"
  Application.OnTime Now() + TimeValue("00:00:10"), "OkGo", schedule:=True
 
End Sub


Sub OkGo()
  ActiveSheet.Cells.Select
End Sub
Yes! Perfect! Thank you very much,

Jeffrey Mahoney 🥃

 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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