By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Access VBA to insert picture in excel spreadsheet

100+
P: 126
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. But with the following Access VBA code, I am getting "Type Mismatch" error at line #13.

Please kindly let me know how to solve this issue.

Thanks a million in advance!

Excel VBA:
Expand|Select|Wrap|Line Numbers
  1. Sub InsertPic()
  2.    Dim myPict As Picture
  3.     With ActiveSheet.Range("A1")
  4.         Set myPict = .Parent.Pictures.Insert("C:\ExportFile\calendar.gif")
  5.         myPict.Top = .Top
  6.         myPict.Left = .Left
  7.         myPict.Placement = xlMoveAndSize
  8.     End With
  9. End Sub
Access VBA:

Expand|Select|Wrap|Line Numbers
  1. Sub InsertPic()
  2. Dim xlApp As Excel.Application, xlWB As Excel.Workbook, xlWS As Excel.Worksheet
  3. Dim myPict As Picture
  4. Set xlApp = New Excel.Application
  5.  
  6. With xlApp
  7. .Visible = True
  8. .Interactive = True
  9. Set xlWB = .Workbooks.Open("C:\Book1.xls", , False)
  10. Set xlWS = xlWB.Worksheets("Example")
  11. xlWS.Activate
  12. With xlWS.Range("A1")
  13.     Set myPict = .Parent.Pictures.Insert("C:\ExportFile\calendar.gif")
  14.     myPict.Top = .Top
  15.     myPict.Left = .Left
  16.     myPict.Placement = xlMoveAndSize
  17. End With
  18. End With
  19. Exit_Routine:
  20. Set xlApp = Nothing
  21. Set xlWB = Nothing
  22. Exit Sub
  23. End Sub
Sep 2 '08 #1
Share this Question
Share on Google+
3 Replies


FishVal
Expert 2.5K+
P: 2,653
Hello.

Declare myPict variable with library qualifier.
Expand|Select|Wrap|Line Numbers
  1. Dim myPict As Excel.Picture
  2.  
Regards,
Fish
Sep 2 '08 #2

100+
P: 126
Thanks a lot!

it is working perfectly fine :)
Sep 2 '08 #3

FishVal
Expert 2.5K+
P: 2,653
You are quite welcome.

Best regards,
Fish
Sep 2 '08 #4

Post your reply

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