Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is an example that I need confirmed as a bug:
1. Create a new workbook 2. On Worksheet 3, insert a named range named "Test" in Cell A1 3. On Worksheet 2, insert a form check box (forms toolbar) and reference "Test" as the linked cell. In the Alternative Text, enter this: "CB_Sheet2_ReferencesSheet3_NamedRange_test" 4. On Worksheet 2, insert a form check box (forms toolbar) and reference "C1" as the linked cell. In the Alternative Text, enter this: "CB_Sheet2_ReferencesSelf_C1" 5. On Worksheet 1, insert a form check box (forms toolbar) and reference "A1" as the linked cell. In the Alternative Text, enter this: "CB_Sheet1_ReferencesSelf_A1" NOTE: Don't use the selector tool to reference the cell, just type it in manually. Press Alt+F11, and insert the following Module code (not in a form's module or the thiswoorkbook module): Public Function GetShapeProps() Dim rngShapeRef As Range Dim wks As Worksheet Dim wks1 As Worksheet Dim sh As Shape For Each wks In ThisWorkbook.Worksheets wks.Activate Debug.Print "ActiveSheet: " & wks.Name Dim intCounter As Integer intCounter = 1 For Each wks1 In ThisWorkbook.Worksheets For Each sh In wks1.Shapes Set rngShapeRef = Range(sh.ControlFormat.LinkedCell) Debug.Print intCounter & ": " & sh.AlternativeText & ": " & rngShapeRef.Address(External:=True) intCounter = intCounter + 1 Next Next Debug.Print "" Next End Function Run that code and look at the results: ActiveSheet: Sheet1 1: CB_Sheet1_ReferencesSelf_A1: [Book1]Sheet1!$A$1 2: CB_Sheet2_ReferencesSheet3_NamedRange_test: [Book1]Sheet3!$A$1 3: CB_Sheet2_ReferencesSelf_C1: [Book1]Sheet1!$C$1 ActiveSheet: Sheet2 1: CB_Sheet1_ReferencesSelf_A1: [Book1]Sheet2!$A$1 2: CB_Sheet2_ReferencesSheet3_NamedRange_test: [Book1]Sheet3!$A$1 3: CB_Sheet2_ReferencesSelf_C1: [Book1]Sheet2!$C$1 ActiveSheet: Sheet3 1: CB_Sheet1_ReferencesSelf_A1: [Book1]Sheet3!$A$1 2: CB_Sheet2_ReferencesSheet3_NamedRange_test: [Book1]Sheet3!$A$1 3: CB_Sheet2_ReferencesSelf_C1: [Book1]Sheet3!$C$1 Either 1 or 3 will be incorrect based on the active sheet, and if the active sheet houses neither one, then both are wrong!!! So, the reason I stumbled on this problem is that I've been asked to document a workbook with many worksheets, thousands of named references, and hundreds of controls. NOTE: These are not necessarily workbook that I have control over for changes to be made. It is someone elses hard work and I'm to document it, but not make changes to it. I'm attempting to write code to document all cell references (yes, I have the cell reference code down), but this object/shape reference is really messed up! I think I have a workaround: Loop the names collection to see if the ControlFormat.LinkedCell is a named range or not. If it is, then use the code, otherwise use the following line instead: Debug.Print intCounter & ": " & sh.AlternativeText & ": [" & ThisWorkbook.Name & "]" & wks1.Name & "!" & rngShapeRef.Address Someone please confirm I'm not seeing things or if there is an alternative to looping the names collection for every object (it would be a loop over 180 times) and string comparison. It adds a lot of time to the documentation procedure that checks for the true address of the linked cell. Also, this workaround is still not foolproof: What if the spreadsheet I'm documenting has a named range named "A1" or "C1" (yes someone *might* actually do this). Which is the control referencing? I've not tested that yet, but this is a big nasty bug for my documentation purposes. Does anyone have a better way to get the *correct* cell reference every time? Please NO PM as I am using my "spam" mailbox to post this with. Please reply here. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
OFFSET function in named range returning wrong # of rows | Excel Worksheet Functions | |||
HLOOKUP using a named range returns #VALUE! | Excel Worksheet Functions | |||
getting the absolute range address from a dynamic named range | Excel Programming | |||
Address of named range | Excel Worksheet Functions | |||
Named range returns 1004 error | Excel Programming |