user3508196
user3508196

Reputation: 39

Selecting a property with a variable name

Dim i As Integer
i = 1
ActiveWorkbook.Worksheets(1).Label & i.Caption = "Checked"

I get a syntax error for the above code, could someone please help me specify a property name as a variable so that I could do things like running this through a for loop to apply this to multiple labels.

Thanks.

Upvotes: 0

Views: 34

Answers (1)

Doug Glancy
Doug Glancy

Reputation: 27488

If it's a Form control, then:

ActiveWorkbook.Worksheets(1).Shapes("Label " & i).TextFrame.Characters.Text  = "Checked"

If it's an ActiveX contol:

ActiveWorkbook.Worksheets(1).OLEObjects("Label" & i).Object.Caption = "Checked"

Upvotes: 1

Related Questions