- 帖子
- 23
- 主題
- 0
- 精華
- 0
- 積分
- 73
- 點名
- 105
- 作業系統
- XP
- 軟體版本
- Office 2003
- 閱讀權限
- 20
- 註冊時間
- 2012-4-21
- 最後登錄
- 2025-4-29
           
|
2#
發表於 2015-7-26 09:15
| 只看該作者
各位大大好,小弟最近在練習訊息方塊,限定時間後消失功能
但請問如何設定時間內沒選擇,自動選取類似"中止 ...
lichang 發表於 2015-7-26 00:15 
不管有沒有選取,訊息方塊功能都會關閉,你可以針對訊息方塊的回傳值來加上對應的處理程序...
參考說明:
https://technet.microsoft.com/en-us/library/ee156593.aspx
範例:- Option Explicit
- Sub Ex()
- 'Windows Script Host Object Model設定引用項目
- Dim myWsh As IWshRuntimeLibrary.WshShell
- Dim intClicked As Integer
- Dim intDefaultButton As Integer: intDefaultButton = vbDefaultButton1
-
- Set myWsh = CreateObject("Wscript.Shell")
- intClicked = myWsh.PopUp(Text:="WSH測試", _
- SecondsToWait:=2, Title:="WSHPopUp", Type:=vbAbortRetryIgnore + intDefaultButton)
-
- Debug.Print intClicked
-
- If -1 = intClicked Then ' 回傳值 (-1) = 設定時間內沒選擇
- If vbDefaultButton1 = intDefaultButton Then
- intClicked = vbAbort
- ElseIf vbDefaultButton2 = intDefaultButton Then
- intClicked = vbRetry
- ElseIf vbDefaultButton3 = intDefaultButton Then
- intClicked = vbIgnore
- End If
- End If
-
- Select Case intClicked
- Case vbAbort
- '加上 [中止] 對應處理程序
- Case vbRetry
- '加上 [重試] 對應處理程序
- Case vbIgnore
- ' ...
- Case Else
- ' ...
- End Select
-
- Set myWsh = Nothing '釋放物件
- End Sub
複製代碼 |
|