I have code in workbook A that opens and does stuff to workbook B. Code runs fine when workbook A and B are the only excel files open (or if workbook A is the only file open). However, if I open up any additional workbook (call it workbook C), the macro does not run correctly. It doesn't cause an error message, it just runs to completion without doing any of the "stuff" it's supposed to do (the stuff is basically finding things in workbook B and pasting them into workbook A).
FWIW, I have done the following simple experiment:
- Open all 3 workbooks (A, B, & C)
- select workbook C so that it is active and the front window
- run the code workbookB.sheet1.activate (this is not verbatim, I know this code as written will fail)
When I do the above test, it doesn't even make workbook B the active workbook. Again, it doesn't cause excel to throw an error message, it just runs and leave workbook C as the active workbook.
Edit: I've tested more, the code below should change the value of a cell in workbook B, but instead is putting the value into workbook C. I am very confused, since workbook C is not referenced in any way (the module is in workbook A)
Sub test()
Dim wb As Workbook
Set wb = Workbooks.Open("U:\workbookB.xlsx")
wb.Worksheets("ED").Range("Z1").Value = "TEST"
End Sub
Edit 2: The issue was occurring when Workbook A and B had been open for several hours, and Workbook C was recently opened. I closed workbook B then re-ran the code and it is working correctly. This leading me to believe that there IS some sort of issue with multiple instances of excel opening. While this is hopefully low-risk, I am still curious if anyone has some way I could code around it as a precaution? Thanks!