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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Keith Faulkner
    New Member
    • Nov 2010
    • 2

    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"

    Code:
     Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Dim PicLocation As String
    Dim myPict As Excel.Picture
    
    
     Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    xlBook.Application.Visible = True
    
    Set xlSheet = xlBook.Worksheets.Add
    
    xlSheet.Name = "Invoices Totals"
    
    
    xlSheet.Activate
    
             PicLocation = "C:\foldername\picture1.bmp"
                If Dir(PicLocation) <> "" Then
                    With xlSheet.Range("L1")
                        Set myPict = .Parent.Pictures.Insert(PicLocation)
                        myPict.Top = .Top
                        myPict.Left = .Left
                        myPict.Placement = xlMoveAndSize
                        
                    End With
                End If
    I have also tried to import the bimtap which is stored in table "Copyright" in field "logo" using

    Code:
    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
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    You can experiment with the following code, but you are on your own:
    Code:
    'False      Link to File
    'True       Save with Document
    'All below values are in Points
    'Left       100
    'Top        100
    'Width       70
    'Height      70
    xlSheet.Shapes.AddPicture PicLocation, False, True, 100, 100, 70, 70

    Comment

    • Keith Faulkner
      New Member
      • Nov 2010
      • 2

      #3
      That did the trick - many thanks

      Keith

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Glad it worked out for you, wasn't really sure whether or not that it would.

        Comment

        Working...