View Full Version : [SOLVED:] A text box in excel that contains a Picture taken from a file
simora
01-23-2017, 02:43 PM
How can I create a text box in excel that contains a Picture taken from a specific folder ?
My folder is @ "C:\PeopleFolder\"
I want to create an InputBox on a worksheet so that when I enter a name, it looks up the image name and inserts the corresponding image into a cell if it exists.
I'll link a TextBox on the worksheet to that cell to display the image.
How is this doable ?
VBA or Worksheet solution; Doesn't matter.
shah1419
01-23-2017, 08:40 PM
use this
Sub Picture()Dim picname As String
Range("B1").Select 'This is where picture will be inserted
picname = Range("A1") 'This is the picture name
On Error Resume Next
'delete previous pic
ActiveSheet.Pictures("ProfilePicture").Delete
Err.Clear
Err.Number = 0
On Error GoTo 0
If (Dir("C:\Users\JINOOB\Desktop\I A\" & picname & ".jpg") = vbNullString) Then Exit Sub
ActiveSheet.Pictures.Insert("C:\Users\JINOOB\Desktop\I A\" & picname & ".jpg").Select 'Path to where pictures are stored
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This resizes the picture
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
With Selection
.Name = "ProfilePicture"
.Left = Range("B1").Left
.Top = Range("B1").Top
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 95#
.ShapeRange.Width = 80#
.ShapeRange.Rotation = 0#
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If (Intersect(Target, Range("A1")) Is Nothing) Then
Exit Sub End If
mikerickson
01-23-2017, 08:42 PM
Something like
Sub test()
Dim picPath As String
picPath = Application.GetOpenFilename
If picPath = "False" Then Exit Sub
ActiveSheet.Shapes("TextBox 1").Fill.UserPicture picPath
End Sub
simora
01-24-2017, 05:34 AM
shah1419 (http://www.vbaexpress.com/forum/member.php?62731-shah1419):
Thanks. That code worked great.
mikerickson : (http://www.vbaexpress.com/forum/member.php?10706-mikerickson)
Another way to do it. That worked also. Thanks
Great guys.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.