Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
leo leo is offline
external usenet poster
 
Posts: 74
Default Back to Previous Sheet (Leo)

Hi,
In an individual large workbook, I put these codes in ThisWorkbook module to
get back previous sheet I navigate;

Public CurrentSheet As Worksheet

Private Sub Workbook_Open()
Application.OnKey "^+B", "thisworkbook.GoBack"
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set CurrentSheet = Sh
End Sub

Public Sub GoBack()
If Not CurrentSheet Is Nothing Then CurrentSheet.Activate
End Sub

so when I move to another sheet in a large workbook containing many sheets,
I can go back to previous one just by pressing Ctrl+Shif+B.
This works fine for an individual workbook, but when I tried to copy the
same on my AddIn to use it for all open or new workbooks, it failed, and the
code did nothing. It seems that CurrentSheet Variable is always Nothing.
I appreciate if you would tell me what is wrong, and how can I fix it??!
--
Thans & Best regards
Leo, InfoSeeker
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Back to Previous Sheet (Leo)

If you have that code in the ThisWorkbook module of your addin, then
it will only work in that addin. Sounds to me like this might call
for a class module at the application level.
Chip has a nice page dedicated to class modules. Have a look.
http://cpearson.com/excel/Classes.aspx

Leo wrote:
Hi,
In an individual large workbook, I put these codes in ThisWorkbook module to
get back previous sheet I navigate;

Public CurrentSheet As Worksheet

Private Sub Workbook_Open()
Application.OnKey "^+B", "thisworkbook.GoBack"
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set CurrentSheet = Sh
End Sub

Public Sub GoBack()
If Not CurrentSheet Is Nothing Then CurrentSheet.Activate
End Sub

so when I move to another sheet in a large workbook containing many sheets,
I can go back to previous one just by pressing Ctrl+Shif+B.
This works fine for an individual workbook, but when I tried to copy the
same on my AddIn to use it for all open or new workbooks, it failed, and the
code did nothing. It seems that CurrentSheet Variable is always Nothing.
I appreciate if you would tell me what is wrong, and how can I fix it??!
--
Thans & Best regards
Leo, InfoSeeker


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Going back to previous worksheet Martin Parker[_2_] Excel Programming 3 March 22nd 07 03:04 PM
back to previous sheet Miri Excel Programming 1 January 29th 07 07:07 AM
Go back to previous page Gary''s Student Excel Programming 0 December 5th 06 09:02 PM
go back/previous cell jasminesy Excel Programming 4 May 24th 06 04:02 PM
Go back to previous worksheet BarryL New Users to Excel 2 May 5th 05 01:38 AM


All times are GMT +1. The time now is 07:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"