簡體   English   中英

如何更改此語句以添加另一個 If?

[英]How can I change this statement to add another If?

我正在使用以下代碼查找活動的“Internet Explorer”窗口並與之交互。 如果用戶沒有打開 Internet Explorer 窗口,我會嘗試添加一個消息框彈出窗口,而不是僅僅收到 VBA 錯誤。 這是我當前的代碼:

For Each GetIE In CreateObject("Shell.Application").Windows() 'Loop to find
If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then Exit For 'Found!
Next GetIE

我想補充的是:

If Not GetIE.Name = "Internet Explorer" Then
MsgBox ("You do not have an active Internet Explorer window open")
End IF

但是當我在第一個代碼的正下方添加它時,它不起作用並給了我一個錯誤。 我沒有寫頂部部分,不確定如何更改它以實現消息框。 任何幫助表示贊賞。

試試這個方法,請:

Sub testFindIE()
 Dim GetIE As Object, boolFound As Boolean
 For Each GetIE In CreateObject("Shell.Application").Windows()
    If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then
        boolFound = True
        Exit For
    End If
 Next GetIE
 If Not boolFound Then MsgBox "You do not have an active Internet Explorer window open"
End Sub

暫無
暫無

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

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