LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Shape ControlFormat.LinkedCell returns wrong Address for named

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OFFSET function in named range returning wrong # of rows Heidi Excel Worksheet Functions 5 March 20th 07 10:15 PM
HLOOKUP using a named range returns #VALUE! MicheleO Excel Worksheet Functions 2 August 24th 06 06:06 PM
getting the absolute range address from a dynamic named range junoon Excel Programming 2 March 21st 06 01:29 PM
Address of named range pcress Excel Worksheet Functions 3 November 13th 04 08:50 AM
Named range returns 1004 error Stu D. Excel Programming 0 September 3rd 04 09:37 AM


All times are GMT +1. The time now is 02:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"