?
Solved

Referencing a control in an Excel Spreadsheet

Posted on 2003-02-25
7
Medium Priority
?
198 Views
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

Help.

0
Comment
Question by:RudeMan
7 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8016269
Try this

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

Expert Comment

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

Author Comment

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

-2147418113 (8000ffff)
Method 'Picture' of object "IImage" failed
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:Glowman
ID: 8016407
Rude,
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.
G
0
 

Author Comment

by:RudeMan
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.
0
 
LVL 3

Accepted Solution

by:
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

0
 

Author Comment

by:RudeMan
ID: 8016883
Thanks Doc, great stuff!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

579 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