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.
Bookmarks