drom
Well-known Member
- Joined
- Mar 20, 2005
- Messages
- 543
- Office Version
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
Hi and thanks in advance!
I have the following code:
I am trying to Activate the book ; thisworkbook, but any of the following codes work:
No matter If I use:
I only get the desired action when using F8 inside my VBA code
I have the following code:
Code:
Sub AAA()
On Error Resume Next: Application.ScreenUpdating = True
'ActiveWindow.Visible = True
Dim wActWkb As String: wActWkb = ActiveWorkbook.Name
Dim wThisWkb As String: wThisWkb = ThisWorkbook.Name
'Application.ScreenUpdating = True
' Workbooks(wThisWkb).Activate
' Windows(wThisWkb).Activate
' ThisWorkbook.Activate
'Application.ScreenUpdating = False
Application.Wait Now() + TimeValue("00:00:01")
Debug.Print wThisWkb, ActiveWorkbook.Name, WKBnew.Name, ActiveWorkbook.Name
'I get:
'AAA.xlsm AAA.xlsm BBB.xlsm AAA.xlsm
If wThisWkb <> ActiveWorkbook.Name Or WKBnew.Name = ActiveWorkbook.Name Then
ThisWorkbook.Activate
End If
X = X
Debug.Print wThisWkb, ActiveWorkbook.Name, WKBnew.Name, ActiveWorkbook.Name 'XXXXXXX
'I get:
'AAA.xlsm AAA.xlsm BBB.xlsm AAA.xlsm
'BUT If I put a Stop within the row: 'XXXXXXX and I press F8 step byt Step I get
'AAA.xlsm BBB.xlsm BBB.xlsm BBB.xlsm
What's going ON???
I am trying to Activate the book ; thisworkbook, but any of the following codes work:
Code:
Sub AAA()
Dim wActWkb As String: wActWkb = ActiveWorkbook.Name
Dim wThisWkb As String: wThisWkb = ThisWorkbook.Name
Application.ScreenUpdating = True
Workbooks(wThisWkb).Activate
Windows(wThisWkb).Activate
ThisWorkbook.Activate
end sub
No matter If I use:
Code:
Sub AAA()
Dim ActWkb As Workbook: set ActWkb = ActiveWorkbook.Name
Dim ThisWkb As Workbook: set ThisWkb = ThisWorkbook.Name
Application.ScreenUpdating = True
ThisWkb.Activate
Windows(ThisWkb.name).Activate
Windows(ThisWkb.fullname).Activate
ThisWorkbook.Activate
end sub
I only get the desired action when using F8 inside my VBA code