473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 13177
ADezii
8,834 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,834 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. Also, Whatever the USER ENETRS needs to go to the...
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 for me. I know how to insert from a textfile,but...
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 database table column. I am using .NET 2.0 only. What...
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 can be done via the import external data tool in...
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 to the Edit alternative. I believe that it must be...
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 error message. please check this code and advise me. ...
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 spread sheet with picture on cell A(1,1) Can...
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 fine and I am able to insert picture in "A1" cell....
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 Number lee 300.00 ...
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 TABLE. I'll give an example : Say ive written the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.