Página 1 de 1

Bloquear combobox com base em resposta anterior

Enviado: 11 Nov 2020 às 17:29
por liviafrias
Olá,

Gostaria de saber como bloquear um combobox active x de acordo com uma resposta anterior. Para ilustrar anexei um exemplo: se eu responder não à pergunta 1 gostaria que as caixas referentes 1.1 e 1.2 fossem desabilitadas.

Pelo que já pesquisei existe as possibilidades de enable e visible pro combobox mas não estou sabendo integrar à macro que já existe (referente aos botões on/off)

A macro que estou usando para os botões de on/off é

Sub PrimeiroBotao()
'Macro definidora das atividades por detrás do primeiro botão de resposta

Application.ScreenUpdating = True

Dim botao1 As String
Dim botao2 As String
Dim botao3 As String
Dim NomeSheet As String

'Dim shp1 As Shape
'Dim shp2 As Shape
'Dim shp3 As Shape

NomeSheet = ActiveSheet.Range("V1")
botao1 = "botao1_Q" & NomeSheet
botao2 = "botao2_Q" & NomeSheet
botao3 = "botao3_Q" & NomeSheet

Set shp1 = ActiveSheet.Shapes(botao1)
Set shp2 = ActiveSheet.Shapes(botao2)
Set shp3 = ActiveSheet.Shapes(botao3)

' Mudar posição e cor

If ActiveSheet.Range("A1") = "On" Then
shp1.Select
With Selection
.ShapeRange.IncrementLeft -38
.ShapeRange.Fill.ForeColor.RGB = RGB(175, 171, 171)
End With
ActiveSheet.Range("A1") = "Off"
ActiveSheet.Range("A1").Activate
Else
shp1.Select
With Selection
.ShapeRange.IncrementLeft 38
.ShapeRange.Fill.ForeColor.RGB = RGB(89, 192, 213)
End With

If ActiveSheet.Range("B1") = "On" Then
shp2.Select
With Selection
.ShapeRange.IncrementLeft -38
.ShapeRange.Fill.ForeColor.RGB = RGB(175, 171, 171)
End With
ActiveSheet.Range("B1") = "Off"
End If
If ActiveSheet.Range("C1") = "On" Then
shp3.Select
With Selection
.ShapeRange.IncrementLeft -38
.ShapeRange.Fill.ForeColor.RGB = RGB(175, 171, 171)
End With
ActiveSheet.Range("C1") = "Off"
End If

ActiveSheet.Range("A1") = "On"
ActiveSheet.Range("E1") = 1
ActiveSheet.Range("A1").Activate
End If

Application.ScreenUpdating = False

End Sub

Agradeceria muito a ajuda!

Re: Bloquear combobox com base em resposta anterior

Enviado: 11 Nov 2020 às 18:28
por osvaldomp
O primeiro comando abaixo desabilita e o segundo oculta. Veja se aproveita algum deles.

ActiveSheet.OLEObjects("Combobox1").Enabled = True 'False
ActiveSheet.OLEObjects("Combobox1").Visible = True 'False


Na Sub PrimeiroBotao():
1. para desabilitar ou ocultar coloque o comando abaixo desta linha ~~~> If ActiveSheet.Range("A1") = "On" Then ~~~> com a opção True.

2. para reabilitar ou reexibir coloque o comando abaixo desta linha ~~~> Else ~~~> com a opção False