+ Reply to Thread
Results 1 to 8 of 8

Go back to previous active sheet

Hybrid View

  1. #1
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Go back to previous active sheet

    You don't need a Class module (*cough*) or an Add-In.

    If you put this in the ThisWorkbook code module of your PersonalMacroWorkbook, the sub BounceBack will return you to the most recently used worksheet from any open workbook to any open workbook.

    After copy pasting, it will not work until you close your Excel and re-open it. Edit the short-cut key to your taste.

    ' in ThisWorkbook code module (of Personal Macro Workbook)
    
    'Option Private Module
    
    Public WithEvents myApp As Application
    Public LastViewedSheet As Worksheet
    
    Private Sub myApp_SheetDeactivate(ByVal Sh As Object)
        Set LastViewedSheet = Sh
    End Sub
    
    Private Sub myApp_WorkbookDeactivate(ByVal Wb As Workbook)
        Set LastViewedSheet = Wb.ActiveSheet
    End Sub
    
    Private Sub Workbook_Open()
        Set myApp = Me.Application
        Application.MacroOptions Macro:="PersonalMacroWorkbook.xlsm!ThisWorkbook.BounceBack", _
            Description:="", ShortcutKey:="y"
    End Sub
    
    Sub BounceBack()
        If Not ThisWorkbook.LastViewedSheet Is Nothing Then
            On Error GoTo myError
            ThisWorkbook.LastViewedSheet.Activate
            Exit Sub
        End If
    myError:
        Beep
    End Sub
    (*cough*) ThisWorkbook, sheet and user form code modules are all code modules of Objects and can accept the kind of coding that a Class Module can take. In a sense, the built in Excel object code modules are Class modules.
    Last edited by mikerickson; 12-02-2014 at 09:47 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] back to previous active sheet ?
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2014, 04:45 PM
  2. Macro to go back to the last active sheet and hide the active sheet
    By yatahaze in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 08:18 AM
  3. Replies: 1
    Last Post: 07-07-2014, 09:19 AM
  4. [SOLVED] Go back to previous active sheet (Excel 2007)
    By JawD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2012, 08:00 AM
  5. Hyperlink refers back to previous sheet?
    By simonwilliams in forum Excel General
    Replies: 8
    Last Post: 12-09-2009, 07:23 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