Import picture file name along with photo into cell

brundag5

New Member
Joined
Jan 23, 2014
Messages
17
Hello. Thanks in advance for your time.

I use the below macro to import pictures into cells and resize the photo. It works great. However I would also like to import the text from the file name (minus the file extension) and past that into an adjacent cell (15 cells below the active cell). Is this possible? Thanks!


Sub InsertPic()
Dim PicLocation As Variant

PicLocation = Application.GetOpenFilename()
If PicLocation = False Then
Range("B32") = ""
Else
ActiveSheet.Shapes.AddPicture(PicLocation, False, True, ActiveCell.Left, ActiveCell.Top, 246, 176).Select
With Selection
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Rotation = 0#
Selection.ShapeRange.IncrementTop 2
Selection.ShapeRange.IncrementLeft 2

End With
End If
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Okay, I've made some progress. Below almost does what I want. However, it imports the whole photo location string along with the name. I'm just looking for the imported picture name. Any suggestions?

Sub InsertPic()
Dim PicLocation As Variant

PicLocation = Application.GetOpenFilename()
If PicLocation = False Then
Range("B32") = ""
Else
ActiveSheet.Shapes.AddPicture(PicLocation, False, True, ActiveCell.Left, ActiveCell.Top, 246, 176).Select
With Selection
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Rotation = 0#
Selection.ShapeRange.IncrementTop 2
Selection.ShapeRange.IncrementLeft 2
'Selection.Copy
GetPName = PicLocation
ActiveCell.Offset(15, 0).Select
ActiveCell = GetPName
'ActiveSheet.Range("B21") = GetPName

End With
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,489
Members
449,166
Latest member
hokjock

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