Consulting

Results 1 to 7 of 7

Thread: List Controls on Worksheet

  1. #1
    VBAX Regular
    Joined
    Oct 2005
    Location
    Westhoughton, England
    Posts
    47
    Location

    List Controls on Worksheet

    Hi all,

    I have a number of ProgressBar controls on a worksheet and would like to be able to use a For Each loop to go through them to find the one(s) I want. Is there any way to do this?

    I've got as far as
    [VBA]Dim pBar as ProgressBar
    For Each pBar In Sheet11.????
    code...
    Next pBar[/VBA]
    but cannot see any collection of controls for Sheet11.

    Any help appreciated, thanks.
    Neil Belch
    Senior Software Technician
    CDL Production Services Ltd

    The views opinions and judgements expressed in this message are solely those of the author.
    The message contents have not been reviewed or approved by CDL.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Whee do these controls come from?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2005
    Location
    Westhoughton, England
    Posts
    47
    Location
    I added them to the worksheet from the control toolbox, so they are 'floating' on the sheet, not on any form.

    I can access each ProgressBar control separately using Sheet11.progBar1, Sheet11.progBar2, etc but I need to access the collection so I can run through them with a For loop.
    Neil Belch
    Senior Software Technician
    CDL Production Services Ltd

    The views opinions and judgements expressed in this message are solely those of the author.
    The message contents have not been reviewed or approved by CDL.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim OLEobj As OLEObject

    For Each OLEobj In ActiveSheet.OLEObjects
    If TypeName(OLEobj.Object) = "ProgressBar" Then
    Debug.Print OLEobj.Name
    End If
    Next OLEobj
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Oct 2005
    Location
    Westhoughton, England
    Posts
    47
    Location
    I ran the code which output each ProgressBar control Name to the Immediate window - now is there any way to edit the Value property of each ProgressBar whilst in that For loop? I tried OLEobj.Value but I get the "object doesn't support this property or method" error.
    Thanks,
    Neil Belch
    Senior Software Technician
    CDL Production Services Ltd

    The views opinions and judgements expressed in this message are solely those of the author.
    The message contents have not been reviewed or approved by CDL.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is probably OLEObj.Object.Value that is the property.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Oct 2005
    Location
    Westhoughton, England
    Posts
    47
    Location
    Thanks, I'll give it a try when I have a chance and let you know how it goes.
    Neil Belch
    Senior Software Technician
    CDL Production Services Ltd

    The views opinions and judgements expressed in this message are solely those of the author.
    The message contents have not been reviewed or approved by CDL.

Posting Permissions

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