matteobusetti
New Member
- Joined
- Aug 23, 2015
- Messages
- 6
Hi all,
I am writing a macro that has to open another workbook (wb2), run a macro in wb2, copy some data and paste it to the first workbook.
However, given it takes some time for Application.Run to actually populate the excel cells in wb2, it seems like the macro i am writing selects the range to copy and copies it before Application.Run has populated the cells and therefore copy empty cells.
Is there a way to tell VBA to wait until Application.Run has populated the entire wb2 before proceeding with selecting the range to copy?
Many thanks
Matteo
I am writing a macro that has to open another workbook (wb2), run a macro in wb2, copy some data and paste it to the first workbook.
However, given it takes some time for Application.Run to actually populate the excel cells in wb2, it seems like the macro i am writing selects the range to copy and copies it before Application.Run has populated the cells and therefore copy empty cells.
Is there a way to tell VBA to wait until Application.Run has populated the entire wb2 before proceeding with selecting the range to copy?
Many thanks
Matteo
Code:
Sub Import_Data1()
' Import_Data1 Macro
'set current workbook
Set wb1 = ActiveWorkbook
Set ws1 = wb1.Worksheets("Performance")
'open IB API workbook
Set wb2 = Workbooks.Open("Workbook2")
Set ws2 = wb2.Worksheets("Portfolio")
'Selects tab
Sheets("Portfolio").Select
'enter username
Range("B5").Select
ActiveCell.FormulaR1C1 = "username"
'run macro in IB API file to get portfolio data
Application.Run "TwsDde.xls!Sheet15.subscribeToPorts"
'select first 20 rows and copy
Range("A8:B28").Select
Selection.Copy