[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 728
  • Last Modified:

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.
0
u795696
Asked:
u795696
1 Solution
 
Michael FowlerSolutions ConsultantCommented:
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

0
 
u795696Author Commented:
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.....
0
 
Michael FowlerSolutions ConsultantCommented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

0
 
Chris BottomleyCommented:
Retry Michaels code with late binding:

Chris
Sub tt()
   Dim sh As object
   Dim s As object
   Dim o As object
   
   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

0
 
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now