[RESOLVIDO] Manipular Controle por Variável

lima27

01-10-2016 19:45:57

Boa tarde, pessoal

Estou com um problema e não consigo resolver.
Gostaria de manipular o valor de um controle utilizando variáveis.

Na célula A1 de uma Sheet tenho o nome do controle "optionbutton1" (mas pode ser optionbutton2, optionbutton3 e optionbutton4)

Tenho um formulário com as options buttons citadas acima (01 a 04). Quando abro o formulário, gostaria que o nome da option button fosse identificado na célula A1 e essa apresentasse o value = True.

Então fiz assim, mas não funcionou:

Código: Selecionar todos

 Private Sub UserForm_Initialize()

Dim OPT As Object
OPT = Worksheets("Pasta 1").Range("A1").Text

    OPT.Value = True

End Sub 
Alguém pode me ajudar?

Mikel Silveira Fraga

01-10-2016 22:08:32

Lima, boa noite.

Tente com o código abaixo:

Código: Selecionar todos

Private Sub UserForm_Initialize()

Dim OPT As Object
Dim nomeControl As String

nomeControl = Worksheets("Plan1").Range("A1").Text

Set OPT = Me.Controls.Item(nomeControl)
OPT.Value = True

End Sub
Teste e nos retorne.

Abraços e bom final de semana.

lima27

02-10-2016 00:32:12

Prezado Mikel,

Funcionou perfeitamente bem!
Muito obrigado!

Um abraço,
Mikel Silveira Fraga escreveu:Lima, boa noite.

Tente com o código abaixo:

Código: Selecionar todos

Private Sub UserForm_Initialize()

Dim OPT As Object
Dim nomeControl As String

nomeControl = Worksheets("Plan1").Range("A1").Text

Set OPT = Me.Controls.Item(nomeControl)
OPT.Value = True

End Sub
Teste e nos retorne.

Abraços e bom final de semana.