简体   繁体   English

是/否按钮VBA Excel。 if-else函数不起作用

[英]Yes/No Button VBA Excel. The if-else function is not working

What I'm trying to achieve is that when you click yes the first user form should appear, if no the other user from should show: 我想要实现的是,当您单击“ ”时,应该显示第一个用户表单,如果没有 ,则应显示其他用户:

Private Sub btnDataSecurity_Click()

Question = MsgBox("Is this client specific", vbYesNo)

If vbYes Then

With DBUnilever
    .StartUpPosition = 2
    .Top = (Application.Height / 2)
    .Left = (Application.Width / 2)
    .Show
End With
Unload Me

Else

With DataBreach
    .StartUpPosition = 2
    .Top = (Application.Height / 2)
    .Left = (Application.Width / 2)
    .Show
End With

End If

Unload Me

End Sub

The if-else function is not working for me. if-else函数对我不起作用。 I don't know what went wrong. 我不知道出了什么问题。 Can someone please help me with this? 有人可以帮我吗?

Consider replacing: 考虑更换:

If vbYes Then

with: 有:

If Question = vbYes Then

(there may be other errors in the posted code) (发布的代码中可能还有其他错误)

As Gary's Student said, you should replace: If vbYes Then with If Question = vbYes Then . 正如Gary的学生所说,您应该替换: If vbYes Then替换为If Question = vbYes Then Since you posted the whole Sub and there's no Dim for Question , make sure that you're declaring it (as an Integer , 'cause that's the return type of MsgBox ) before it's usage. 由于您发布了整个Sub,并且没有Dim for Question ,因此请确保在使用前声明它(作为Integer ,因为这是MsgBox的返回类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM