F Fraggs Apr 13, 2004 #1 How can I create a generic back button for my workbook, so that it goe to the last view worksheet? Is this even possible
How can I create a generic back button for my workbook, so that it goe to the last view worksheet? Is this even possible
B Bob Phillips Apr 13, 2004 #2 Fraggs, Put this code in the ThisWorkbook code module Public prevWs As Worksheet Private Sub Workbook_Open() Set prevWs = ActiveSheet End Sub Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) Set prevWs = Sh End Sub and add this code to a standard code m odule and tie your button to it Sub PrevSheet() ThisWorkbook.prevWs.Activate End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct)
Fraggs, Put this code in the ThisWorkbook code module Public prevWs As Worksheet Private Sub Workbook_Open() Set prevWs = ActiveSheet End Sub Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) Set prevWs = Sh End Sub and add this code to a standard code m odule and tie your button to it Sub PrevSheet() ThisWorkbook.prevWs.Activate End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct)
O Otto Moehrbach Apr 13, 2004 #3 One way: Code in a regular module: Public OldSheetName As String Public mySheetName As String Sub ReturnToLastSheet() Worksheets(OldSheetName).Activate End Sub Code in the Thisworkbook object: Private Sub Workbook_Open() MySheetName = "Sheet1" 'Change as appropriate End Sub Private Sub Workbook_SheetActivate(ByVal Sh As Object) OldSheetName = mySheetName mySheetName = Sh.Name End Sub Then assign the ReturnToLastSheet macro to a button. HTH Otto
One way: Code in a regular module: Public OldSheetName As String Public mySheetName As String Sub ReturnToLastSheet() Worksheets(OldSheetName).Activate End Sub Code in the Thisworkbook object: Private Sub Workbook_Open() MySheetName = "Sheet1" 'Change as appropriate End Sub Private Sub Workbook_SheetActivate(ByVal Sh As Object) OldSheetName = mySheetName mySheetName = Sh.Name End Sub Then assign the ReturnToLastSheet macro to a button. HTH Otto