Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Toggle between two workbooks via MACRO

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,327
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Toggle between two workbooks via MACRO

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to all workbooks [email protected] New Users to Excel 0 February 27th 08 12:01 PM
macro boxes: toggle on/off Peter Excel Discussion (Misc queries) 1 October 5th 07 09:34 AM
Toggle comments on or off macro Jim G Excel Discussion (Misc queries) 3 October 5th 06 04:07 AM
workbook Protection Toggle Macro Just Learning Excel Discussion (Misc queries) 3 August 30th 05 11:03 PM
Macro in all workbooks Pam Coleman Excel Discussion (Misc queries) 2 February 24th 05 07:49 PM


All times are GMT +1. The time now is 03:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"