ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loading a JPG into an Excel worksheet (https://www.excelbanter.com/excel-programming/384964-loading-jpg-into-excel-worksheet.html)

TedT

Loading a JPG into an Excel worksheet
 
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

MrScience

Loading a JPG into an Excel worksheet
 
On Mar 9, 8:04 pm, TedT wrote:
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")


TedT

Loading a JPG into an Excel worksheet
 
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

"MrScience" wrote:

On Mar 9, 8:04 pm, TedT wrote:
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")



Peter T

Loading a JPG into an Excel worksheet
 
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


"TedT" wrote in message
...
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

"MrScience" wrote:

On Mar 9, 8:04 pm, TedT wrote:
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")





TedT

Loading a JPG into an Excel worksheet
 
All works fine!
Thanks a lot!
TedT

"Peter T" wrote:

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


"TedT" wrote in message
...
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

"MrScience" wrote:

On Mar 9, 8:04 pm, TedT wrote:
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")







All times are GMT +1. The time now is 01:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com