yinkajewole
Active Member
- Joined
- Nov 23, 2018
- Messages
- 281
I have pictures on range F7 in all sheets. unfortunately the names of the picture varies in all the sheets. how do i give it a uniform name like "mypic"
Can you select one of pictures and run this in the immediate window:
?Selection.TopLeftCell.Address
Do you get F7 ?
I got this $F$7
Function PicFromRange(ByVal R As Range) As Shape
Dim shp As Shape
For Each shp In R.Worksheet.Shapes
If shp.TopLeftCell.Address = R.Address Then
[COLOR=#0000ff][B] Debug.Print shp.ControlFormat.Parent.Name & vbTab & shp.Name & vbTab & shp.TopLeftCell.Address[/B][/COLOR]
Set PicFromRange = shp: Exit Function
End If
Next shp
End Function
Well in that case my code should work ...
If you amend the PicFromRange function as follows and re-run the Test sub again, do you get the sheest, shapes and respective topleft cells in the immediate window?
Code:Function PicFromRange(ByVal R As Range) As Shape Dim shp As Shape For Each shp In R.Worksheet.Shapes If shp.TopLeftCell.Address = R.Address Then [COLOR=#0000ff][B] Debug.Print shp.ControlFormat.Parent.Name & vbTab & shp.Name & vbTab & shp.TopLeftCell.Address[/B][/COLOR] Set PicFromRange = shp: Exit Function End If Next shp End Function
I got nothing....
When I pressed F8 to run the code line by line, when it got to the function, it did nothing, it then went to end function - that's what I notice