472,325 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

How to insert a picture into Excel sheet from Access VBA?

I am trying to add a logo from a bitmap file to an Excel report which is created using MS Access 2010.
This code works, but it inserts the bitmap as a linked file. So when I view the excel file on another workstation which does not have the bitmap, the logo is shown with the message "The Linked Image cannot be displayed"

Expand|Select|Wrap|Line Numbers
  1.  Dim xlApp As Excel.Application
  2. Dim xlBook As Excel.Workbook
  3. Dim xlSheet As Excel.Worksheet
  4. Dim PicLocation As String
  5. Dim myPict As Excel.Picture
  6.  
  7.  
  8.  Set xlApp = CreateObject("Excel.Application")
  9. Set xlBook = xlApp.Workbooks.Add
  10. xlBook.Application.Visible = True
  11.  
  12. Set xlSheet = xlBook.Worksheets.Add
  13.  
  14. xlSheet.Name = "Invoices Totals"
  15.  
  16.  
  17. xlSheet.Activate
  18.  
  19.          PicLocation = "C:\foldername\picture1.bmp"
  20.             If Dir(PicLocation) <> "" Then
  21.                 With xlSheet.Range("L1")
  22.                     Set myPict = .Parent.Pictures.Insert(PicLocation)
  23.                     myPict.Top = .Top
  24.                     myPict.Left = .Left
  25.                     myPict.Placement = xlMoveAndSize
  26.  
  27.                 End With
  28.             End If
I have also tried to import the bimtap which is stored in table "Copyright" in field "logo" using

Expand|Select|Wrap|Line Numbers
  1. PicLocation = DLookup("logo", "copyright")
I use this succesfully to place logos on all PDF reports that are created but when I try to use this to export to Excel it fails with
"Unable to get the Insert property of the picture class"

Any suggestions on how to make this an embedded image on the Excel file would be gratefully recieved, by whichever method.

Regards

Keith
Nov 15 '10 #1

✓ answered by ADezii

You can experiment with the following code, but you are on your own:
Expand|Select|Wrap|Line Numbers
  1. 'False      Link to File
  2. 'True       Save with Document
  3. 'All below values are in Points
  4. 'Left       100
  5. 'Top        100
  6. 'Width       70
  7. 'Height      70
  8. xlSheet.Shapes.AddPicture PicLocation, False, True, 100, 100, 70, 70

3 12888
ADezii
8,832 Expert 8TB
You can experiment with the following code, but you are on your own:
Expand|Select|Wrap|Line Numbers
  1. 'False      Link to File
  2. 'True       Save with Document
  3. 'All below values are in Points
  4. 'Left       100
  5. 'Top        100
  6. 'Width       70
  7. 'Height      70
  8. xlSheet.Shapes.AddPicture PicLocation, False, True, 100, 100, 70, 70
Nov 17 '10 #2
That did the trick - many thanks

Keith
Nov 19 '10 #3
ADezii
8,832 Expert 8TB
Glad it worked out for you, wasn't really sure whether or not that it would.
Nov 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet....
0
by: Mamatha | last post by:
Hi When i clicked a button, i want to insert data from listview in VB.NET to Excel sheet. If you know the solution either above or below is ok...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a...
1
by: Patonar | last post by:
Hi, I would like to be able to using VBA from an Excel macro - go through each line in my spreadsheet and add to a database. I know that this...
2
by: bbasberg | last post by:
I have been working hard to clean up my code but I am still wondering why all incoming records go to the "AddNew" part of the IF statement and never...
0
by: imtmub | last post by:
Hi All, when i am trying to insert records from excel sheet to wko table in my database. My Excel sheet contains 400 records. I am getting the...
1
by: monadel | last post by:
I have a problem insering a picture into excel spread sheet from access. What I am trying to do is when user press a button it will create a excel...
3
by: JFKJr | last post by:
Hello everyone, I am trying to insert a picture in an excel spreadsheet cell using Access VBA. The following excel VBA code is working perfectly...
1
kirubagari
by: kirubagari | last post by:
Hai experts, How to duplicate the data from 1 excel sheet to another excel sheet 2. Lets say Name Voucher Value Voucher...
1
by: PeacefulSoul | last post by:
Hello, I have a lot of excel sheets which columns are slightly different, i want to import all of these sheets (one at a time) into ONE SQL...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.