Created
April 7, 2012 20:48
-
-
Save Natim/2332037 to your computer and use it in GitHub Desktop.
Web Browser Back Button in VBA for Office Excel - history.go(-1) in Excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Dim History As New Collection | |
Private Sub Workbook_SheetActivate(ByVal Sh As Object) | |
Dim wksht As Worksheet | |
Set wksht = Sh | |
History.Add wksht | |
If History.Count > 10 Then History.Remove 1 | |
End Sub | |
Sub Go_Back_In_History() | |
If History.Count = 0 Then | |
Sheets(1).Activate | |
Exit Sub | |
End If | |
If History.Count = 1 And History(1).CodeName = ActiveSheet.CodeName Then | |
Sheets(1).Activate | |
Exit Sub | |
End If | |
If History(History.Count).CodeName = ActiveSheet.CodeName Then History.Remove History.Count | |
Application.EnableEvents = False | |
On Error Resume Next | |
History(History.Count).Activate | |
On Error GoTo 0 | |
Application.EnableEvents = True | |
History.Remove History.Count | |
History.Add ActiveSheet | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, sorry about my ignorance, but how do you run both subs from a commandbutton/macro on excel? I can run Go_Back_In_History() by itself but only seems to work if I have to go 'backwards' in the excel file, from one tab to other tab on the left. It doesn't work going back from one tab to a tab on the right...