Referencing a control in an Excel Spreadsheet

Posted on 2003-02-25
Medium Priority
Last Modified: 2010-04-07
How do I reference and embedded image control in an Excel spreadsheet.
I have the open excel object "xlApp" and I want to assign a picture to the image control "Image1" embedded in the first worksheet.

This doesn't work:

xlApp.Worksheets(1).Image1.Picture = Picture1.Picture


Question by:RudeMan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 26

Expert Comment

ID: 8016269
Try this

set xlApp.Worksheets(1).Image1.Picture = Picture1.Picture
LVL 26

Expert Comment

ID: 8016272
By the way, what's the error msg?

Author Comment

ID: 8016344
No, sorry that doesn't work - here is the error msg:

-2147418113 (8000ffff)
Method 'Picture' of object "IImage" failed
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 8016407
In VB to load a picture into an Image control you have to use the LoadPicture() function.  You might want to try to use this.

xlApp.Worksheets(1).Image1.Picture = LoadPicture(App.Path & "/" & Picture1.Picture)

The declare is global in VB so it should be in VBA as well.
Hope this helps.

Author Comment

ID: 8016526
Thanks Glow - but no go.
I think the problem lies with the way of referencing the Image control. I think I might need a special OLE object to manipulate it.

Accepted Solution

DocM earned 200 total points
ID: 8016800

Images are embedded objects. Setting the picture is not one of the manipulation you can carry out under
Excels Object model.
Write the macro in Excel and call it passing in the parameters from VB :

Dim xlApp As New Excel.Application
      With xlApp
        .Workbooks.Open ("C:\My documents\book1.xls")
        .Run "SetPicture", "C:\My documents\House.JPG"
    End With

Write this code in the Excel Workbook:

Sub SetPicture(ImagePathName As String)
    Worksheets(1).Image1.Picture = LoadPicture(ImagePathName)
End Sub


Author Comment

ID: 8016883
Thanks Doc, great stuff!

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question