Reputation: 248
im using visualbasic express. I want to insert image to excel application. I have succeed it. here is the code;
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
oSheet.Shapes.AddPicture("C:\Logo\logo.bmp", False, True, 415, 1, 20, 30)
it works well. But instead of giving the location of the picture ("C:\Logo\logo.bmp"), i want to put the image itself. I mean i want to change the last line like this:
oSheet.Shapes.AddPicture(Me.Picturebox1.image , False, True, 415, 1, 20, 30)
But it does not work. Is there a way to insert picture to excel without using the location?
Upvotes: 4
Views: 9758
Reputation: 536
Unfortunately I'm pretty sure there's no way to add the image without using a file name. According to the MSDN docs for Shapes, there does not appear to be any overload of AddPicture
that takes anything other than a string to determine what image you want to insert.
Is the goal here to add the image that you don't necessarily have on disk somewhere (or don't know where on disc it is)? If that's the case, you can get the location (path or URI) of the image with the ImageLocation
property and pass that to AddPicture
. You could also first save the image to disk using Image.Save()
and the pass the new path to AddPicture
.
Upvotes: 2