Hello,
I'm writing a script for a database integration project using multiple upload sheets and I need to delete all contents from all worksheets and then refresh all SQL queries before running the conversion scripts that I'm calling from seperate modules (I have a tad bit of OCD when it comes to seperating my scripts) but the problem I'm running into is the script looks for certain column headers. So while the SQL query is still grabbing data, my script is looking for headers that don't exist yet. I've tried multiple wait functions and can't find one that allows the SQL statement to continue while it waits. Any help would be greatly appreciated. Thanks. Sample code below.
Sub MasterSub()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.UsedRange.ClearContents
Next ws
ActiveWorkbook.RefreshAll
Sheets("Products").Select
Call ProductsModule.Products
Sheets("BoM").Select
Call BoMModule.BoM
Sheets("Category").Select
Call CategoryModule.Category
End Sub
Nick
EDIT Solved. The only way I found the SQL statement would continue to run while waiting is the application.ontime method where the coding looked like this:
Sub MasterSub()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.UsedRange.ClearContents
Next ws
Application.ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue("00:00:10"), Procedure:="TimeDelay"
End Sub
Function TimeDelay()
Sheets("Products").Select
Call ProductsModule.Products
Sheets("BoM").Select
Call BoMModule.BoM
Sheets("Category").Select
Call CategoryModule.Category
End Function
EDIT Even better, Data Range Properties for the external data import has a box that says Background Refreshing! Unchecked this and everything worked....... figures I missed it
Bookmarks