1

After I run a macro(which selects records from sql server, no reference to another workbook), one of the other open workbooks is randomly activate.
The macro is in book1, I run the macro from book1.
At the end, book2(or book3 etc) is activate. Why ?!
I tried to put just before End Sub

Dim Wb As Workbook  
Set Wb = Active/ThisWorkbook  
Wb.Activate   

or

msgbox "ok"  

but still fly to another open workbook(the message box pop up on book2)
This thing not happens every time, just sometimes, randomly. Thank you

update: Since I fixed a cirrcular refference in book2, seems to stop.

user2284877
  • 138
  • 1
  • 9

1 Answers1

1

See Difference Between ActiveWorkbook and ThisWorkbook

Sub Bus()
Dim Wb As Workbook
Set Wb = ActiveWorkbook
Debug.Print Wb.Name

Set Wb = ThisWorkbook
Debug.Print Wb.Name


End Sub

If you put above code in Book2. Module 1 and Select Book1 and run it

You will get following output in the immediate Window:

Book1
Book2

enter image description here

Community
  • 1
  • 1
Stupid_Intern
  • 3,382
  • 8
  • 37
  • 74