Loading a JPG into an Excel worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have created a button on a spreadsheet that I want to load a JPG Image
into the spreadsheet when it is clicked.

Does anyone know the VB code to do this. I can either overwrite an existing
image of the same name if that is easier, or load it for the first time - but
I also need to control where it loads on the sheet.

The file name is always the same - it is the result of an engineer process
run by the spreadsheet.
Thanks
TedT
 
Hi,
I have created a button on a spreadsheet that I want to load a JPG Image
into the spreadsheet when it is clicked.

Does anyone know the VB code to do this. I can either overwrite an existing
image of the same name if that is easier, or load it for the first time - but
I also need to control where it loads on the sheet.

The file name is always the same - it is the result of an engineer process
run by the spreadsheet.
Thanks
TedT

ActiveSheet.Pictures.Insert ("C:\filePath\myPicture.jpg")
 
Thanks for you help, that works. But it has identified another problem....
Clicking the button reloads the image over itself, so I need to delete the
image before loading. But the iamge's name seems to keep changing. How can
I find out the name of the image before I try to delete it? Excel seems to
assign an arbitrary name like "picture15" to it and the fiel name does not
seem to be used.

Thanks
TedT
 
Sub test()
Dim pic As Picture

On Error Resume Next
Set pic = ActiveSheet.Pictures("myPictureName")
On Error GoTo errH

If Not pic Is Nothing Then
pic.Delete
End If

Set pic = ActiveSheet.Pictures.Insert("C:\filePath\myPicture.jpg")
pic.Name = "myPictureName"

With Range("C3")
pic.Left = .Left
pic.Top = .Top
End With
'pic.Select

Exit Sub

errH:
MsgBox Err.Description

End Sub


Regards,
Peter T
 
All works fine!
Thanks a lot!
TedT

Peter T said:
Sub test()
Dim pic As Picture

On Error Resume Next
Set pic = ActiveSheet.Pictures("myPictureName")
On Error GoTo errH

If Not pic Is Nothing Then
pic.Delete
End If

Set pic = ActiveSheet.Pictures.Insert("C:\filePath\myPicture.jpg")
pic.Name = "myPictureName"

With Range("C3")
pic.Left = .Left
pic.Top = .Top
End With
'pic.Select

Exit Sub

errH:
MsgBox Err.Description

End Sub


Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top