VBA changes active book

I have a spreadsheet where in VBA it disables the opening of other spreadsheets and temporarily sets them to active worksheet.

However, I have a loop, and at the end of the first iteration I need to set the active worksheet as the source that launched the VBA module. I cannot set a new object Workbookto open the original, because the original is still open in the background and it says that it is already open.

My problem is that I need to change the active Workbookto the original when I never had a workbook object to reference it.

'Original workbook is active implicitly

'loop begins

'change active workbook to something else


'Need to change back to original workbook here- but don't have a VBA workbook object

'end of loop
+5
source share
1 answer

ThisWorkbook, , .

Dim Wb As Workbook
Set Wb = ActiveWorkbook

, , ThisWorkbook

Sub Test()
Dim Wb As Workbook
Dim Wb2 As Workbook
Set Wb = ThisWorkbook
For Each Wb2 In Application.Workbooks
    Wb2.Activate
Next
Wb.Activate
End Sub
+13

All Articles