Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put picture in Excel document 1

Status
Not open for further replies.

rikeman

Programmer
Sep 18, 2004
40
BE
Hello,

I would like to put a picture from a picturebox (or a picture file) in an excel file using Visual basic.
I've got following declarations:

Dim xlsApp As excel.Application
Set xlsApp = excel.Application

and with those declarations I do some processes (like filling in a cell and look for values in cells)

But I want to insert a picture in that Excel document, how must I do that?

Greetz.
 
Assuming that you've declared xlSheet to refer to the Active sheet:

xlSheet.Pictures.Insert ("C:\MyPic.JPG")

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
How can you say in wich cell excel must put the picture?
 
It will be inserted at the currently selected cell, so just select the cell immediately before the Insert.

With ActiveSheet
.Cells(10, 10).Select
.Pictures.Insert ("C:\MyPic.JPG")
End With


A good tip for simple Excel operations is to use the Macro recorder in Excel, then copy the code across (with suitable mods) into your VB app.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thanx for this valuable post! Just one more question: I also would place a border on cells A1:A5 (only on the bottom, not arround cell). Any idea how I must do that?
 
Open Excel.
Go to View|Toolbars and make sure that Borders is checked (so you can see the border toolbar)
Go to Tools|Macros|Record New Macro.
Accept defaults for Macro
Select Cells A1:A5
Select the appropriate Border from the Borders Toolbar
Go to Tools|Macros|Stop Recording
Go to Tools|Macros|VB Editor
Select Modules|Module 1
Voila! Your code is sitting there in Macro 1 ready to edit and Copy&Paste into VB!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
The code to insert a picture in excel works perfect! But when I want to put a picture in an excel spreadsheet in visual basic, it doesn't work. Must I use another code to do that? (You can insert a spreadsheet by inserting the component 'Microsoft Office XP Web components')

Regards,
Rikeman.
 
Open the application from VB, not just a picture!

Did you read faq222-2244 yet? It advises that you keep one thread to one question so that others may also learn from it. For a new topic it's best to start a new thread.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top