Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
WOW! That's perfect!!! Thank you.
-- Aligi "Harald Staff" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
macro to all workbooks | New Users to Excel | |||
macro boxes: toggle on/off | Excel Discussion (Misc queries) | |||
Toggle comments on or off macro | Excel Discussion (Misc queries) | |||
workbook Protection Toggle Macro | Excel Discussion (Misc queries) | |||
Macro in all workbooks | Excel Discussion (Misc queries) |