+ Reply to Thread
Results 1 to 8 of 8

How to, check if a picture object exist

  1. #1
    Kevin McCartney
    Guest

    How to, check if a picture object exist

    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

  2. #2
    Norman Jones
    Guest

    Re: How to, check if a picture object exist

    Hi Kevin,

    Try:

    Dim myPic As Picture

    Set myPic = ws.Pictures("LOGO_1")


    ---
    Regards,
    Norman



    "Kevin McCartney" <[email protected]> wrote in
    message news:[email protected]...
    > 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




  3. #3
    Kevin McCartney
    Guest

    Re: How to, check if a picture object exist

    No, that doesn't work, or what library reference are you using?

    "Norman Jones" wrote:

    > Hi Kevin,
    >
    > Try:
    >
    > Dim myPic As Picture
    >
    > Set myPic = ws.Pictures("LOGO_1")
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Kevin McCartney" <[email protected]> wrote in
    > message news:[email protected]...
    > > 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

    >
    >
    >


  4. #4
    Norman Jones
    Guest

    Re: How to, check if a picture object exist

    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
    '<<=============

    ---
    Regards,
    Norman



  5. #5
    Norman Jones
    Guest

    Re: How to, check if a picture object exist

    Hi Kevin,

    > Set myPic = ws.Pictures("LOGO_1")


    should be:

    On Error Resume Next
    Set myPic = ws.Pictures("LOGO_1")
    On Error GoTo 0

    ---
    Regards,
    Norman



  6. #6
    Tom Ogilvy
    Guest

    Re: How to, check if a picture object exist

    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

    --
    Regards,
    Tom Ogilvy




    "Kevin McCartney" wrote:

    > No, that doesn't work, or what library reference are you using?
    >
    > "Norman Jones" wrote:
    >
    > > Hi Kevin,
    > >
    > > Try:
    > >
    > > Dim myPic As Picture
    > >
    > > Set myPic = ws.Pictures("LOGO_1")
    > >
    > >
    > > ---
    > > Regards,
    > > Norman
    > >
    > >
    > >
    > > "Kevin McCartney" <[email protected]> wrote in
    > > message news:[email protected]...
    > > > 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

    > >
    > >
    > >


  7. #7
    Kevin McCartney
    Guest

    Re: How to, check if a picture object exist

    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



    "Tom Ogilvy" wrote:

    > 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
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    >
    > "Kevin McCartney" wrote:
    >
    > > No, that doesn't work, or what library reference are you using?
    > >
    > > "Norman Jones" wrote:
    > >
    > > > Hi Kevin,
    > > >
    > > > Try:
    > > >
    > > > Dim myPic As Picture
    > > >
    > > > Set myPic = ws.Pictures("LOGO_1")
    > > >
    > > >
    > > > ---
    > > > Regards,
    > > > Norman
    > > >
    > > >
    > > >
    > > > "Kevin McCartney" <[email protected]> wrote in
    > > > message news:[email protected]...
    > > > > 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
    > > >
    > > >
    > > >


  8. #8
    Kevin McCartney
    Guest

    Re: How to, check if a picture object exist

    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

    "Kevin McCartney" wrote:

    > 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
    >
    >
    >
    > "Tom Ogilvy" wrote:
    >
    > > 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
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > >
    > >
    > > "Kevin McCartney" wrote:
    > >
    > > > No, that doesn't work, or what library reference are you using?
    > > >
    > > > "Norman Jones" wrote:
    > > >
    > > > > Hi Kevin,
    > > > >
    > > > > Try:
    > > > >
    > > > > Dim myPic As Picture
    > > > >
    > > > > Set myPic = ws.Pictures("LOGO_1")
    > > > >
    > > > >
    > > > > ---
    > > > > Regards,
    > > > > Norman
    > > > >
    > > > >
    > > > >
    > > > > "Kevin McCartney" <[email protected]> wrote in
    > > > > message news:[email protected]...
    > > > > > 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
    > > > >
    > > > >
    > > > >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1