Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Code to switch between workbooks | Excel Programming | |||
Using alt-tab to switch between Excel workbooks under the same session | Excel Discussion (Misc queries) | |||
How to switch between different workbooks? | Excel Programming | |||
Switch Workbooks | Excel Programming | |||
Switch between workbooks | Excel Programming |