I have an excel file titled "MBGR". This is my main file. Now, through this file, i executed a batch file and as a result, some data is extracted from a database application and gets pasted in a newly generated excel file titled "Volla".
So, now i have two workbooks open at the same time. Now, i want to copy this newly generated data back to my original workbook "MGBR". The problem is that the database extraction takes like 5 seconds and VBA code is moving forward. It commands excel to:
Activate the newly generated workbook "Volla"
Copy the data
Paste back to originial workbook "MGBR"
The data base extraction is still in process when excel recives the command to activate the "Volla" sheet which havent been generated yet, so the code crashes. Obviously, if i break the two processes in two indendent modules, it works fine but how can i add a pause so that the "Volla" sheet gets generated and then the copying command starts. Pause or Sleep does not work as it halts all excel activtiies. For your review, i am attaching the code
Sub Routine()
batch = Sheets("input").Range("p3") & "\" & "Script.bat"
Open batch For Output As #1
Close #1
Open batch For Output As #1
Print #1, """" & "C:\Program Files (x86)\HEC\HEC-DSSVue\HEC-DSSVue.exe" & """" & " " & """" & path & """"
Close #1
''Executing batch file - The batch file gets executed here and the New excel _
sheet will be generated
retval = Shell(batch, vbNormalFocus)
Windows("volla.xls").Activate '' This command gives error as workbook "Volla"
' generation was still under process
ActiveSheet.Range("a6:z1000").Copy
Windows("MGBR").Activate
With Sheets("test")
.Range("a1").PasteSpecial Paste:=xlPasteValues
End With
Application.DisplayAlerts = False
Windows("volla.xls").Close
Any help????