469,366 Members | 2,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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 12362
ADezii
8,800 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,800 Expert 8TB
Glad it worked out for you, wasn't really sure whether or not that it would.
Nov 19 '10 #4

Post your reply

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

Similar topics

14 posts views Thread by pmud | last post: by
9 posts views Thread by dba123 | last post: by
1 post views Thread by Patonar | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.