devilzhead
03-01-2012, 07:55 AM
Hello everyone,
I am trying to find out a way where I can insert a picture in the active worksheet. The name of the picture is displayed in Cell A2. I want VBA to read the the picture name and find that particular file name in a specified folder or the same folder as the workbook and then insert the picture in one of the cells.
I know it is simple but I am getting a hard time. I searched for adding a picture code and was not very helpful. I have got something which is shown below.
Dim NameFound As Range
Dim fPath As String
Dim sImageCell As String
With Cells(2, 1)
TextBox1.Text = Cells(Row, 1)
Set NameFound = .Find(TextBox1.Value)
If NameFound Is Nothing Then
MsgBox ("Picture of") & TextBox1.Value & ("Not Found")
Else
With NameFound
fPath = ThisWorkbook.Path & "\"
Pcit = LoadPicture(fPath & "\" & TextBox1.Value & ".jpg")
'Select the cell where the picture has to be placed
GetCell:
Set PictCell = Application.InputBox("Select the cell to insert into", Type:=8)
If PictCell.Count > 1 Then MsgBox "Select ONE cell only": GoTo GetCell
PictCell.Select
'MsgBox ("Picture of") & TextBox1.Value
End With
End If
End With
Next
End Sub
***************************************
I am using clicking function to add the picture. After PictCell.Select I get stuck. I tried insert method and it does not work.
Any help in this matter will be greatly appreciated. Thanks.
I am trying to find out a way where I can insert a picture in the active worksheet. The name of the picture is displayed in Cell A2. I want VBA to read the the picture name and find that particular file name in a specified folder or the same folder as the workbook and then insert the picture in one of the cells.
I know it is simple but I am getting a hard time. I searched for adding a picture code and was not very helpful. I have got something which is shown below.
Dim NameFound As Range
Dim fPath As String
Dim sImageCell As String
With Cells(2, 1)
TextBox1.Text = Cells(Row, 1)
Set NameFound = .Find(TextBox1.Value)
If NameFound Is Nothing Then
MsgBox ("Picture of") & TextBox1.Value & ("Not Found")
Else
With NameFound
fPath = ThisWorkbook.Path & "\"
Pcit = LoadPicture(fPath & "\" & TextBox1.Value & ".jpg")
'Select the cell where the picture has to be placed
GetCell:
Set PictCell = Application.InputBox("Select the cell to insert into", Type:=8)
If PictCell.Count > 1 Then MsgBox "Select ONE cell only": GoTo GetCell
PictCell.Select
'MsgBox ("Picture of") & TextBox1.Value
End With
End If
End With
Next
End Sub
***************************************
I am using clicking function to add the picture. After PictCell.Select I get stuck. I tried insert method and it does not work.
Any help in this matter will be greatly appreciated. Thanks.