ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   InserPictureInRange method for excel VBA (https://www.excelbanter.com/excel-programming/404455-inserpictureinrange-method-excel-vba.html)

the excel-arator

InserPictureInRange method for excel VBA
 
I found a snippit of code on an excel help website which is supposed to
insert a picture into a range of cells. However, when the code is run, I get
a compile error saying the sub or function is not defined. Should the code
below work? And if not, does anyone have any ideas on how to insert a picture
into a specified range of cells? The only way I know of is the "addpicture"
method where you have to specify in points where the image is insert, and how
large to make the image.
Using cell references for sizing and placement would be alot easier! I'm new
to VBA, so simplified explanations would be appreciated!

Here's the code I found:

Sub TestInsertPictureInRange()
InsertPictureInRange "C:\FolderName\PictureFileName.gif", _
Range("B5:D10")
End Sub

Thanks for you help!

Ron de Bruin

InserPictureInRange method for excel VBA
 
This is not a standard function of Excel

You can also use this

Sub Test()
Dim myPict As Picture
With ActiveSheet.Range("B5")
Set myPict = .Parent.Pictures.Insert("C:\FolderName\PictureFile Name.gif")
myPict.Top = .Top
'myPict.Width = .Width
'myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"the excel-arator" <the wrote in message
...
I found a snippit of code on an excel help website which is supposed to
insert a picture into a range of cells. However, when the code is run, I get
a compile error saying the sub or function is not defined. Should the code
below work? And if not, does anyone have any ideas on how to insert a picture
into a specified range of cells? The only way I know of is the "addpicture"
method where you have to specify in points where the image is insert, and how
large to make the image.
Using cell references for sizing and placement would be alot easier! I'm new
to VBA, so simplified explanations would be appreciated!

Here's the code I found:

Sub TestInsertPictureInRange()
InsertPictureInRange "C:\FolderName\PictureFileName.gif", _
Range("B5:D10")
End Sub

Thanks for you help!



the excel-arator[_2_]

InserPictureInRange method for excel VBA
 
That works well, thanks a lot!

"Ron de Bruin" wrote:

This is not a standard function of Excel

You can also use this

Sub Test()
Dim myPict As Picture
With ActiveSheet.Range("B5")
Set myPict = .Parent.Pictures.Insert("C:\FolderName\PictureFile Name.gif")
myPict.Top = .Top
'myPict.Width = .Width
'myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"the excel-arator" <the wrote in message
...
I found a snippit of code on an excel help website which is supposed to
insert a picture into a range of cells. However, when the code is run, I get
a compile error saying the sub or function is not defined. Should the code
below work? And if not, does anyone have any ideas on how to insert a picture
into a specified range of cells? The only way I know of is the "addpicture"
method where you have to specify in points where the image is insert, and how
large to make the image.
Using cell references for sizing and placement would be alot easier! I'm new
to VBA, so simplified explanations would be appreciated!

Here's the code I found:

Sub TestInsertPictureInRange()
InsertPictureInRange "C:\FolderName\PictureFileName.gif", _
Range("B5:D10")
End Sub

Thanks for you help!




Lazzaroni

InserPictureInRange method for excel VBA
 
ActiveSheet.Shapes.AddPicture
"http://www.google.com/intl/en_ALL/images/logo.gif", msoTrue, msoFalse, 0, 0,
10, 10

I used to use that to link images (not embed) in Excel 2003 spreadsheets. In
Excel 2003 you could use AddPicture and a URL in place of a local image
filename, and you could enable and disable linking and embedding. That
prevented your workbook from choking on embedded images.

With the advent of Excel 2007 AddPicture no longer accepts URLs in place of
local image file names. See:

http://support.microsoft.com/kb/928983/en-us

Now I use the following code, which does not allow for enabling linking and
disabling embedding, that I am awa

Dim MyPicture As Shape
Set MyPicture = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 0, 0, 10, 10)
MyPicture.Fill.UserPicture "http://www.google.com/intl/en_ALL/images/logo.gif"

UserPicture can accept a URL in place of a local image file name, but I
haven't figured out how to enable linking and disable embedding when using
UserPicture.

Can anyone suggest a way to insert an image from either a local file name or
a URL and still enable linking and disable embedding?

Thanks for your help.

TFriis

InserPictureInRange method for excel VBA
 
Thank you - I was looking for that code :)

This is not a standard function of Excel

You can also use this

Sub Test()
Dim myPict As Picture
With ActiveSheet.Range("B5")
Set myPict = .Parent.Pictures.Insert("C:\FolderName
\PictureFileName.gif")
myPict.Top = .Top
'myPict.Width = .Width
'myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With
End Sub


All times are GMT +1. The time now is 04:24 AM.

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