Rename pictures in a particular cell

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"
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe something along these lines :
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
            Set PicFromRange = shp: Exit Function
        End If
    Next shp

End Function


Sub Test()

    Dim ws As Worksheet, shp As Shape
    
    For Each ws In ThisWorkbook.Worksheets
        Set shp = PicFromRange(ws.Range("f7"))
        If Not shp Is Nothing Then
            shp.Name = "mypic"
        End If
    Next ws

End Sub
 
Upvote 0
I suppose even though you can set the same name for all pictures, you can not format them at once.
That said, the way to know if a shape is in a range is:
Code:
If Not Intersect(Range(activesheet.shapes(1).TopLeftCell.Address), activesheet.range("A1")) Is Nothing Then DoSomeThing
 
Last edited:
Upvote 0
Maybe something along these lines :
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
            Set PicFromRange = shp: Exit Function
        End If
    Next shp

End Function


Sub Test()

    Dim ws As Worksheet, shp As Shape
    
    For Each ws In ThisWorkbook.Worksheets
        Set shp = PicFromRange(ws.Range("f7"))
        If Not shp Is Nothing Then
            shp.Name = "mypic"
        End If
    Next ws

End Sub

this did not rename the picture as expected
 
Upvote 0
I suppose even though you can set the same name for all pictures, you can not format them at once.
That said, the way to know if a shape is in a range is:
Code:
If Not Intersect(Range(activesheet.shapes(1).TopLeftCell.Address), activesheet.range("A1")) Is Nothing Then DoSomeThing

there are many pictures on the sheet
 
Upvote 0
The pictures TopLeft corner must lie exactly within range F7 - Can you check that ?
 
Upvote 0
I see no use in renaming shapes to a unic name.
What do you want to do specifically (resize, delete, etc.)?
This example rename the shapes that are in "F7" cell range in all sheet of activeworkbook:

Code:
Dim oSheet As Worksheet, oShp As Shape

For Each oSheet In ActiveWorkbook.Sheets
  For Each oShp In oSheet.Shapes
     If Not Intersect(Range(oShp.TopLeftCell.Address), oSheet.Range("F7")) Is Nothing Then oShp.Name = "UnicName"
   Next oShp
Next oSheet
 
Last edited:
Upvote 0
I see no use in renaming shapes to a unic name.
What do you want to do specifically (resize, delete, etc.)?
This example rename the shapes that are in "A1" cell range:

Code:
Dim oSheet as Worksheet, oShp as shape

For Each oSheet in Activeworkbook.Sheets
  For each oShp in oSheet.shapes 
     If Not Intersect(Range(oSheet.oShp.TopLeftCell.Address), oSheet.range("F7")) Is Nothing Then oSheet.oShp.name="UnicName"
   Next oShp
Next oSheet

I want to copy the pictures to another workbook, that's why I need the name
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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
Back
Top