View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Unhiding specific worksheets in VBA (Excel 2003)

Here is one suggestion that seems to work.

The hyperlink fires and meks the sheet visible before linking. Deactivating
the sheet hides it again. It assumes the hyperlinks are all on a sheet
called Master

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Sh.Name < "Master" Then
Sh.Visible = False
End If
End Sub

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
As Hyperlink)
Dim iPos As Long
Application.EnableEvents = False
iPos = InStr(Target.SubAddress, "!")
Worksheets(Left(Target.SubAddress, iPos - 1)).Visible = True
Target.Parent.Hyperlinks(1).Follow
Application.EnableEvents = True
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Jinx" wrote in message
...
One simple means I'll run by the business owner will be to hide the tabs

all
together:
ActiveWindow.DisplayWorkbookTabs = False
Any other suggestions?

"Jinx" wrote:

Hi all,
I have a workbook containing ~60 worksheets in which I would like to

hide
~50 of them but have individual worksheets open on demand. The

worksheets
contain hyperlinks to other worksheets within the same workbook and are
simply referenced as an Excel hyperlink. On clicking a hyperlink I

would
like it to unhide the relevant worksheet, on hitting the Excel Web

'back'
button I would like it to rehide the relevant worksheet.
Is this feasible as currently constructed or am I looking at additional
macros to replace the hyperlinking?
Extract of the code doing the worksheet hiding:
---
Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim wst As Worksheet

'Ensure the Data sheet is hidden and can't be shown without password
ThisWorkbook.Worksheets("Data").Visible = xlVeryHidden

'Ensure the Exchange Rate sheet is hidden and can't be shown without
password
ThisWorkbook.Worksheets("ExchangeRates").Visible = xlVeryHidden

'protect the Worksheets from alteration
For Each wst In ThisWorkbook.Worksheets
wst.Protect (PWORD)
Next wst

'Unprotect the Exchange Rate Worksheet to obtain Reuters updates
ThisWorkbook.Worksheets("ExchangeRates").Unprotect PWORD

'activate the MainMenu worksheet
ThisWorkbook.Worksheets("MainMenu").Activate

'define the data range names
DefineDataColumns

'sort the specifed data ranges
SortDataRanges "Data_AssociatedDealerGroup", "Data_DealerNames",
"Data_DealerIDs"
SortDataRanges "Data_AssociatedUnitCode", "Data_RMCodes"
SortDataRanges "Data_RMUnitCodes", "Data_RMUnitNames"
SortDataRanges "Data_AssDealerGrp", "Data_AssMarginTempl"

Exit_Workbook_open:
Exit Sub
ErrorHandler:
DisplayError Err.Number, Err.Description
Resume Exit_Workbook_open
End Sub
---
Any help will be greatly appreciated - I have read through the other
discussion threads, but I don't see anything specific to my

requirements.
Regards,