nightcrawler23
Well-known Member
- Joined
- Sep 24, 2009
- Messages
- 721
Hi all,
I have a workbook with macros in it. If I make copies of this workbook and open then in different instances of excel i can run the macro in each instance simultaneously (I have tried this). The same thing i want to accomplish using code as each macro takes at least 5 mins to complete.
The below code runs perfectly fine but not the way i wanted . I had to change the code to open the workbook run the code and close them one by one.
i call this code form a userform. I have tried adding DoEvents in the button code. It doesn't help.
Any ideas on how to do this.
I have a workbook with macros in it. If I make copies of this workbook and open then in different instances of excel i can run the macro in each instance simultaneously (I have tried this). The same thing i want to accomplish using code as each macro takes at least 5 mins to complete.
The below code runs perfectly fine but not the way i wanted . I had to change the code to open the workbook run the code and close them one by one.
i call this code form a userform. I have tried adding DoEvents in the button code. It doesn't help.
Any ideas on how to do this.
Code:
Sub runDP()
'/// some code here///
Dim oXl As Excel.Application
Dim oWB As Excel.Workbooks
Dim sceneWB As Excel.Workbook
Dim sceneBatSheet As Excel.Worksheet
Application.DisplayAlerts = False
For i = 1 To lr - 3
Set oXl = New Excel.Application
Set sceneWB = oXl.Workbooks.Open(ThisWorkbook.Path & "\" & batchSheet.Range("B" & (i + 3)) & ".xls") ' open the workbook
Call genScene(oXl, sceneWB, i + 3) ' fill in parameters
oXl.Run ("myMacro") 'run the code
sceneWB.Close (True) 'save and close
oXl.Quit 'close the instance
Set oXl = Nothing
Next i
Application.DisplayAlerts = True
Set oXl = Nothing
End Sub