Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Switch Between Workbooks

I need to toggle between two different open workbooks (these two would be the
only open visible workbooks at the time). The problem is that I don't always
know what the name of the workbooks will be. Could someone please help with
some code that would take the current active workbook, designate that
workbook as WB1, and then designate the other open workbook as WB2. In the
end, I want to be able to switch back and forth through the two as follows:

WB1.Activate
WB2.Activate

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Switch Between Workbooks

Jason,

try something like this. it will only work if there are only 2 open
workbooks.

Sub test()
Dim wb1 As Workbook
Dim wb2 As Workbook

If Workbooks.Count = 2 Then
Set wb1 = ActiveWorkbook
Set wb2 = IIf(Workbooks(1).Name = wb1.Name, Workbooks(2), Workbooks(1))
End If

End Sub



--
Hope that helps.

Vergel Adriano


"Jason" wrote:

I need to toggle between two different open workbooks (these two would be the
only open visible workbooks at the time). The problem is that I don't always
know what the name of the workbooks will be. Could someone please help with
some code that would take the current active workbook, designate that
workbook as WB1, and then designate the other open workbook as WB2. In the
end, I want to be able to switch back and forth through the two as follows:

WB1.Activate
WB2.Activate

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Switch Between Workbooks

Vergel,

This is probably close to what I need, however, the problem is that I have
open the personal.xls folder (which is actually where this code will be
stored). Personal.xls is always a hidden workbook, but it is open
nonetheless. Is there someway to workaround this so it only considers the
open and visible workbooks.

Thanks.



"Vergel Adriano" wrote:

Jason,

try something like this. it will only work if there are only 2 open
workbooks.

Sub test()
Dim wb1 As Workbook
Dim wb2 As Workbook

If Workbooks.Count = 2 Then
Set wb1 = ActiveWorkbook
Set wb2 = IIf(Workbooks(1).Name = wb1.Name, Workbooks(2), Workbooks(1))
End If

End Sub



--
Hope that helps.

Vergel Adriano


"Jason" wrote:

I need to toggle between two different open workbooks (these two would be the
only open visible workbooks at the time). The problem is that I don't always
know what the name of the workbooks will be. Could someone please help with
some code that would take the current active workbook, designate that
workbook as WB1, and then designate the other open workbook as WB2. In the
end, I want to be able to switch back and forth through the two as follows:

WB1.Activate
WB2.Activate

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Switch Between Workbooks

Jason,

Maybe something like this then... it assigns the activeworkbook to wb1 and
then loops through all workbooks to find the next one that is not equal to
the activeworkbook and personal workbook..


Sub test()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim wb As Workbook

Set wb1 = ActiveWorkbook
For Each wb In Workbooks
If wb.Name < wb1.Name And UCase(wb.Name) < "PERSONAL.XLS" Then
Set wb2 = wb
Set wb = Nothing
Exit For
End If
Next wb

End Sub





--
Hope that helps.

Vergel Adriano


"Jason" wrote:

Vergel,

This is probably close to what I need, however, the problem is that I have
open the personal.xls folder (which is actually where this code will be
stored). Personal.xls is always a hidden workbook, but it is open
nonetheless. Is there someway to workaround this so it only considers the
open and visible workbooks.

Thanks.



"Vergel Adriano" wrote:

Jason,

try something like this. it will only work if there are only 2 open
workbooks.

Sub test()
Dim wb1 As Workbook
Dim wb2 As Workbook

If Workbooks.Count = 2 Then
Set wb1 = ActiveWorkbook
Set wb2 = IIf(Workbooks(1).Name = wb1.Name, Workbooks(2), Workbooks(1))
End If

End Sub



--
Hope that helps.

Vergel Adriano


"Jason" wrote:

I need to toggle between two different open workbooks (these two would be the
only open visible workbooks at the time). The problem is that I don't always
know what the name of the workbooks will be. Could someone please help with
some code that would take the current active workbook, designate that
workbook as WB1, and then designate the other open workbook as WB2. In the
end, I want to be able to switch back and forth through the two as follows:

WB1.Activate
WB2.Activate

Thanks.

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
Code to switch between workbooks [email protected] Excel Programming 3 October 11th 06 01:32 AM
Using alt-tab to switch between Excel workbooks under the same session Kjetil Excel Discussion (Misc queries) 0 June 22nd 06 03:39 PM
How to switch between different workbooks? Ivan Excel Programming 2 December 28th 05 06:30 AM
Switch Workbooks Ronbo Excel Programming 1 February 29th 04 06:58 PM
Switch between workbooks Newbie Excel Programming 1 January 7th 04 09:34 PM


All times are GMT +1. The time now is 11:57 AM.

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"