Link to home
Start Free TrialLog in
Avatar of u795696
u795696Flag for Netherlands

asked on

Loop through textboxes based on teaxbox names in text file - VBA

Hello,

I have written some VBA functionality in a program called OSI PI Processbook. This program provides the user to create custom functions using VBA but I am not sure if everything is there.

What I want to do is the following:

I have multiple textboxes on a screen and I want to be able to do some stuff with these textboxes in another event.
The problem is that I am  not able to loop through the textboxes by looping through the objects on the screen, the VBA addin does not support this method.

So I was thinking to put the names of the textboxes in a textfile and then loop through the textfile and do the stuff with the textboxes but I do not know how to do this.

Can somebody please help me out here? I would be glad to provide more information when needed.

Thanks.
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

Are you sure you cannot loop through the objects

Add the attached macro to your work and see if it works

Michael
Sub tt()
   Dim sh As Worksheet
   Dim s As Shape
   Dim o As OLEObject
   
   Set sh = ActiveSheet

   For Each s In sh.Shapes
      MsgBox "Shape - " & s.Name
   Next s

   For Each o In sh.OLEObjects
      MsgBox "Object - " & o.Name
   Next o

   Set sh = Nothing

End Sub

Open in new window

Avatar of u795696

ASKER

I've already tried this approach:

iArr = 1

Do Until iArr = UBound(silo_array, 2)
    Me.OLEObjects("txt" & silo_array(iArr, 1)).Object.Text = "Test"
    iArr = iArr + 1
Loop

Open in new window


But this does not work :(

If I ask for the count of OleObjects in the processbook it return 0.....
Not all textboxes are OLEObjects whereas they are all shapes. Please try the code I posted and see if the loop of shapes works

Michael
Avatar of u795696

ASKER

Unfortunately the program I am working in does not know the object class Shapes. So your example will not work :(

ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.