A macro that is run inside my main macro generates values that I need to copy to another Excel file.
My main macro does not wait for the generating to finish and pastes empty cells into the other document.
The code works as intended if I step through but not when pressing "run".
Set wbThis = ActiveWorkbook
strName = ActiveSheet.Name
Set wbTarget = Workbooks.Open("D:\Users\user37\Desktop\exportas\Information.xlsm")
wbTarget.Worksheets("Information").Activate
ActiveSheet.Range("B2").Value = myValue
Application.Run ("'Information.xlsm'!ExportData")
wbTarget.Worksheets("SO Lines").Activate
ActiveSheet.Range("E4").Copy
Set wbTarget = Workbooks.Open("D:\Users\user37\Desktop\exportas\Sablonai.xlsm")
wbTarget.Worksheets("Duomenys").Activate
ActiveSheet.Range("A1").Select
activeSheet.PasteSpecial
I found several answers to this question but none of them seem to work for me.
I tried the sleep and wait methods. They stop the whole macro even the one that generates values.
I tried adding DoEvents in the end of the generating macro OR after when I call the generating macro in the main macro. The changes have no effect.
Suggested duplicate Excel waiting for one macro to finish before calling another does not help.