# VBA set time delay before running the next macro line



## Raychin (Dec 21, 2022)

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?


```
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
```


----------



## Jeffrey Mahoney (Dec 21, 2022)

Please Try this

```
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
```


----------



## Raychin (Dec 22, 2022)

Jeffrey Mahoney said:


> Please Try this
> 
> ```
> Sub Open_Any_File()
> ...


Yes! Perfect! Thank you very much,
Jeffrey Mahoney 🥃​


----------

