View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Open Workbook Read Only and hide select worksheets

I thought I was following what you want but got lost somewhere along the
line.

Why not hide the requisite sheets in the 'read-only' wb's open event.
Anyway, if you want to run a macro in another workbook you can use the Run
method, eg

Dim sMacro As String
sMacro = "'FileIndex.xls'!ShowMySheetOnly"

Application.Run sMacro

There's a pair of apostrophes bracketing the filename. Normally they are not
necessary but may be required if the filename includes certain characters,
no harm to include the apostrophes even if not required.

Regards,
Peter T

"imelda1ab" wrote in message
...
Something I thought would be so simple has turned into a nightmare. I
need to open a workbook named index.xls Read Only and then hide 25 of
the 26 worksheets. Yes, I tried to create a new workbook and paste
link of the one worksheet I need, but the workbook is heavy laden with
formulae, formatting, etc. so it crashes everytime I attempt to
paste. So, I'm going for Plan II and it has to be dummy proof for the
users. No protection; no passwords; not based on userlogin.

My question is, is there a way to open UserIndex.xls with it's
Workbook_Open code and somehow "call" the macro ShowMySheetOnly to run
in the Read Only? The macros work perfectly separately, but I cannot
figure out how to combine them so the user only has to open the one
document?

What I have for the two docs:

UserIndex.xls opens FileIndex.xls read only:

Sub Workbook_Open()
Workbooks.Open Filename:="C:\medcenter\index.xls",
ReadOnly:=True
Workbooks("index.xls").Activate
End Sub

Hide all worksheets but Sheet1 in FileIndex.xls:
Sub ShowMySheetOnly()
Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Wks.Name < "Sheet1" Then
If Wks.Visible = xlSheetVisible Then Wks.Visible =
xlSheetHidden
End If
Next Wks
End Sub

Thank you to any and all who offer their insight/suggestions, etc.