I have a workbook (wb1) in which I need to compare with data pulled from an external program.
My macro currently extracts data from a third-party app (SAP), which automatically opens a brand new Excel workbook (wb2) that is saved to my PC.
The macro needs to then copy all of the data from wb2 and paste it into wb1.
Sub Extract_Data()
'...'
' Extracting data from third-party app '
'...'
wb2.Activate
' Highlight and copy all cells in rows A to F '
LR = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:F" & LR).Select
Selection.Copy
wb1.Activate
ActiveSheet.Paste
This would usually work just fine, however, when the macro switches windows back to wb1, it automatically switches windows back to wb2.
This happens after ~3 seconds, I think this may be due to the workbook finalizing the saving process? I’m not sure if this is a thing or not.
I have looked all over for a suitable solution but I can’t find anyone else having a similar problem.
Within the macro, after wb2 is created and opened, I have tried:
saving wb2 -> closing it -> reopening it -> then try to copy/paste the cells into wb1.
I run into the same issue with this too.
I’m not sure if this is an issue with saving/syncing, and this causes Excel to reopen the window. For info, when wb2 is created, it is saved onto my “C” drive, and it is not set up to auto-save (OneDrive).
I would appreciate if anyone has any advice for this, or could point me in the direction of any solutions that already exist out there.
2