Refer to codename of worksheet part 2

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,638
Office Version
  1. 2019
Platform
  1. Windows
Further to this discussion:


in particular mikerickson's response:

Rich (BB code):
Sub test()
    MsgBox WorksheetCodeNamed("wksApples").Range("A1").Value
End Sub
Function WorksheetCodeNamed(wsCodeName As String, Optional wb As Workbook)
    If wb Is Nothing Then Set wb = ActiveWorkbook
    
    With wb
        Set WorksheetCodeNamed = .Sheets(.VBProject.VBComponents(wsCodeName).Properties("index").Value)
    End With
End Function

if the worksheet I am seeking is in another workbook, any code in that workbook cannot be password protected.

Why is that?

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
39,044
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Because you can't access properties of the VBProject if it's protected.
 

Forum statistics

Threads
1,171,144
Messages
5,874,034
Members
433,017
Latest member
inxcndd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top