簡體   English   中英

是/否按鈕VBA Excel。 if-else函數不起作用

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

我想要實現的是,當您單擊“ ”時,應該顯示第一個用戶表單,如果沒有 ,則應顯示其他用戶:

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

if-else函數對我不起作用。 我不知道出了什么問題。 有人可以幫我嗎?

考慮更換:

If vbYes Then

有:

If Question = vbYes Then

(發布的代碼中可能還有其他錯誤)

正如Gary的學生所說,您應該替換: If vbYes Then替換為If Question = vbYes Then 由於您發布了整個Sub,並且沒有Dim for Question ,因此請確保在使用前聲明它(作為Integer ,因為這是MsgBox的返回類型)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM