473,395 Members | 1,726 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,395 software developers and data experts.

Access VBA to insert picture in excel spreadsheet

126 100+
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
3 20684
FishVal
2,653 Expert 2GB
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
JFKJr
126 100+
Thanks a lot!

it is working perfectly fine :)
Sep 2 '08 #3
FishVal
2,653 Expert 2GB
You are quite welcome.

Best regards,
Fish
Sep 2 '08 #4

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

Similar topics

0
by: ImraneA | last post by:
Hi there Have a database, where front-end interface allows user to select a ms access database. From there, standard tables are linked. Routine, that creates a spreadsheet, for each table a...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
3
by: deko | last post by:
I've been trying to use the Access Import Wizard to expedite importing data into my mdb. The nice thing about the wizard is that I can import from different file formats - txt, xls, even Outlook -...
6
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be...
1
by: gm | last post by:
Hi; I have written a database that tracks all the installation we have ever done. I have a small heating company. I have recently started keeping a directory of digital photographs of the...
0
by: frankkirchner | last post by:
There has to be a way to get an image into the XSLT transormation process so that it shows up on a Formatted Excel Spreadsheet. When saving an Excel spreadsheet to XML format - you lose the image...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: Tony Hine | last post by:
Problem for Excel Developers One of the problems facing Excel developers moving into MS Access is actually the apparent similarity between MS Access tables and Excel spreadsheets. MS Access is...
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.