How to, check if a picture object exist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi TWIMC

I wanted to check to ensure a picture logo is present on a worksheet before
I moveit.

So something like

Set oleLOGO1 = wst.pictures("LOGO_1")
If not oleLOGO1 is nothing Then
'move actions
End

The only problem is what do I declare the oleLOGO as

e.g.

Dim oleLOGO as Excel.OLEObject because I get an error, "Type mismatch".

Any help much appreciated.

TIA
KM
 
Hi Kevin,

Try:

Dim myPic As Picture

Set myPic = ws.Pictures("LOGO_1")
 
Hi Kevin,
No, that doesn't work, or what library reference are you using?

My test code was:

'=============>>
Public Sub Tester0012()
Dim ws As Worksheet
Dim myPic As Picture

Set ws = Sheets("Sheet1")

Set myPic = ws.Pictures("LOGO_1")

If Not myPic Is Nothing Then
'do something, e.g,:
MsgBox myPic.TopLeftCell.Address
End If

End Sub
'<<=============
 
Why do you think that wouldn't work Kevin?

set ws = Activesheet
? typename(ws.Pictures("LOGO_1"))
Picture

However, if this is actually an image control from the Control Toolbox
Toolbar, then it very well might be an OleObject:

? ws.Pictures(2).Name
CommandButton1
? typename(ws.Pictures(2))
OLEObject

In that case, use the OleObjects collection

If you don't know, then you can

Dim OleLOGO as Object
 
The reason why is that I tried the following but got the same error 13 Type
missmatch

Dim pic2 As Picture

Set pic2 = wst.Pictures("DB_LOGO_1") it breaks on this line


so if I declare pic2 as picture and if write in the imediate window
?typename(wst.Pictures("DB_LOGO_1")) I do get "Picture" as trhe returned
value, so my problem is why doesn't it work, why does pic2 not get set to
DB_LOGO_1 when DB_LOGO_1 is located on the worksheet.

TIA
KM
 
Oh.... I knew why there was a reason why I shouldn't program late in the
night, I miss the obvious, since I'm running this from Access in needed to
declare the pic as Excel.Picture and not just Picture.... silly me, oh well
another lesson learnd.

Cheers all
TIA
KM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top