Home |
Search |
Today's Posts |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom,
I couldn't get that code to work, but I could get a concatenated string to work instead. There is also a small addition to the code below - if there is a space in the sheet name, then you must account for it and concatenate with single quotes. Additional to that, if you have a single quote (apostrophe) in the name already ("Troy's Sheet 1"), there is an even bigger string parse routine that I did not list!!! I've found that using the second set of code below to activate the sheet is the best method. Here is your addition to the code, modified to get the shape parent and concatenate with the shape's linkedcell property: Public Function GetShapeProps() Dim rngShapeRef As Range Dim wks As Worksheet Dim wks1 As Worksheet Dim sh As Shape Dim s As String 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 s = sh.ControlFormat.LinkedCell If InStr(1, s, "!", vbTextCompare) Then Set rngShapeRef = Range(s) Else If InStr(sh.Parent.Name, " ") 0 Then s = "'" & sh.Parent.Name & "'!" & s Else s = sh.Parent.Name & "!" & s End If Set rngShapeRef = Range(s) End If Debug.Print intCounter & ": " & sh.AlternativeText & _ ": " & rngShapeRef.Address(External:=True) intCounter = intCounter + 1 Next Next Debug.Print "" Next End Function Since I'm not a big fan of string parsing, the caveates it presents, or the additional time it takes for larger string operations, I prefer to use the simplest method - Activate the sheet so that unqualified ranges are created using the activesheet as the parent: 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 ' ACTIVATE THE CURRENT SHEET. Reason: Ranges created in code ' will use the activesheet as the parent of a range if the 'range isn't fully qualified. 'e.g.: Fully Qualified range: Sheet1!A1 OR 'Sheet 1'!A1 OR 'Sheet 1'!$A$1, etc 'e.g.: UnQualified range (but completely valid): A1 OR $A$1 wks1.Activate For Each sh In wks1.Shapes Set rngShapeRef = Range(sh.ControlFormat.LinkedCell) Debug.Print intCounter & ": " & sh.AlternativeText & _ ": " & rngShapeRef.Address(External:=True) 'OR if you don't want the Name of the workbook 'Debug.Print intCounter & ": " & sh.AlternativeText & _ ' ": " & rngShapeRef.Parent.Name & "!" & rngShapeRef.Address intCounter = intCounter + 1 Next Next Debug.Print "" Next End Function Also, for anyone else reading this thread, and the code, obviously the first For...Next is not necessary. I only wanted to do it that way for my original post in order to show that the ActiveSheet was showing as the parent when it really wasn't. However, after debating this point with Tom here, it was determined that this is how unqualifed ranges in code are created. Thanks for pointing me in the right direction Tom! |
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 |