Get Name Box value of shape in current region

PressEscape

New Member
Joined
May 2, 2024
Messages
22
Office Version
  1. 2021
Platform
  1. Windows
I wish to get the the name box value of the picture within a selected region with VBA
1718571431395.png

I can navigate and select the region. What's the trick to get the name box value (picture 27) and assign it to a variable?
1718571551542.png
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I may have not explained that the image has not been selected
what do I add to this simple code to select the Name Box Value of the picture within the range

VBA Code:
Sub copyPicture()
   
    Range("C2:C12").Select
          
End Sub

1718579969386.png
 
Upvote 0
Do you know the location of the image in relation to the worksheet? ie:- In relation to the cells that lie beneath the image.
And is the shape static or will it be moved and change its location on the worksheet?

PS: If the image the only shape you have on the worksheet then you can easily retrieve its name based on the index as follows:
VBA Code:
MsgBox Sheet1.Shapes(1).Name
Change the Sheet name as required.
 
Last edited:
Upvote 0
The worksheet has many pictures
the pictures don't move.
I wish to get the picture name from the selected region.
 
Upvote 0
Code:
Sub Select_Shape_In_Selection()
   Dim targetRange As Range
   Set targetRange = Range(Selection.Address)
   Dim shp As Shape
   For Each shp In ActiveSheet.Shapes
      If Not Intersect(targetRange, Range(shp.TopLeftCell, shp.BottomRightCell)) Is Nothing Then MsgBox shp.Name: Exit For
   Next shp
End Sub
 
Upvote 0
Thanks jolivanes,
Not quite what I want. I don't want to loop through all shapes in the worksheet.
I only wish to get the shape in the current range.
 
Upvote 0
I have got the select_shape_In_Selection code writing to debug.print but the picture number returned is a picture nowhere near the current region
(Picture 149 is returned but the picture in current region is Picture 27)
any idea's?
 
Upvote 0

Forum statistics

Threads
1,221,805
Messages
6,162,074
Members
451,738
Latest member
gaseremad

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