Toggle between two workbooks via MACRO
Hi Aligi
Simplified (does not deal with third or more workbooks, implement that in
the For-Next loop):
Sub test()
Dim Wb As Workbook
Dim Other As Workbook
Dim Home As Workbook
Set Home = ThisWorkbook
For Each Wb In Workbooks
If Wb.FullName < Home.FullName Then
Set Other = Wb
Exit For
End If
Next
If Other Is Nothing Then Exit Sub
Home.Activate
MsgBox Home.FullName
Other.Activate
MsgBox Other.FullName
If MsgBox("Home again?", vbYesNo + vbQuestion) = _
vbYes Then
Home.Activate
MsgBox Home.FullName
Else
Other.Activate
MsgBox Other.FullName
End If
End Sub
HTH. Best wishes Harald
"Aligi" skrev i melding
...
I have two workbooks open, one I know the name and it is where I am running
the macro from, the second one I only now that it is open but I may not
know
the name (as it could have been renamed). I need to go to the second
workbook
(and make it active) via a MACRO. Thank you in advanced
Aligi
|