Results 1 to 3 of 3

Switch between Excel Sheets like Windows [Alt]+[Tab] - Solution

Threaded View

  1. #1
    Registered User
    Join Date
    03-24-2014
    Location
    Missouri
    MS-Off Ver
    Excel 2013
    Posts
    2

    Switch between Excel Sheets like Windows [Alt]+[Tab] - Solution

    It has been a long time wish of mine to be able to switch between the new and last viewed Excel spreadsheet like switching between applications using [alt]+[tab] in windows. I have not been satisfied with the solutions I found. One recommendation was to open two versions of the same Excel file and select the two tabs you wanted to switch back and forth between using [alt]+[tab]. Not at all efficient. So, I decided to solve this on my own.

    My solution involves an open workbook event to trigger a class module to define a new class object that keeps track of the last deactivated sheet. A procedure then activates the last deactivated sheet that can be triggered by a shortcut key.

    To start, this code will have to be embedded in your Personal.xlsb file. If you do not know what this file is, read here copy-your-macros-to-a-personal-macro-workbook.

    The following is written assuming you are familiar with the VB editor for Excel. Read here if you are not, managing-macros-with-the-visual-basic-editor.

    In the project explorer (top left), double click the ThisWorkbook object under Microsoft Excel Objects tree and copy this code into it.

    Private Sub Workbook_Open()
        Call Init_SheetToggle(a)
    End Sub
    Insert a new Module and copy this code into it. Name it anything you like. Default is Module1. I renamed mine to m_SheetToggle. You can change the name in the properties window. Display the properties window by pressing [F4] .

    Dim AppObject As New c_SheetToggle
    Public iSheet As String
    Sub Init_SheetToggle(a)
        Set AppObject.AppEvent = Excel.Application
    End Sub
    Sub PriorSheet(sh)
        iSheet = sh.Name
    End Sub
    Sub SheetToggle()
        On Error Resume Next
        Sheets(iSheet).Select
    End Sub
    Insert a new Class Module. Press [F4] and change the name from Class1 to c_SheetToggle. This is not optional! Then, copy this code into it.

    Public WithEvents AppEvent As Application
    Private Sub AppEvent_SheetDeactivate(ByVal sh As Object)
        Call PriorSheet(sh)
    End Sub
    Save and close the VB editor.

    Press [Alt]+[F8] and assign a shortcut key to the newly created routine under options. I have mine as [Ctrl]+[Shift]+Q. You may choose whatever you like.

    Completely close all Excel files and restart Excel.
    Last edited by MR_Jason; 03-28-2014 at 05:14 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Detect attempt to switch between open excel files (windows) during loop
    By lahansen2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-02-2014, 03:10 PM
  2. Microsoft Excel has stopped working.Windows is checking for a solution to the program
    By amarendra19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2011, 02:07 AM
  3. Macro switch between windows question
    By punter in forum Excel General
    Replies: 3
    Last Post: 06-21-2006, 01:15 PM
  4. [SOLVED] Solution to stopping IE opening excel workbooks without changing windows settings
    By Lawrence.Colombo@gmail.com in forum Excel General
    Replies: 0
    Last Post: 05-24-2006, 06:10 AM
  5. [SOLVED] how do I switch from one window to another-clicking on windows
    By crystal in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-30-2005, 04:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1