「でもIf文で直接win.document.Titleを評価しないのはなぜだ?」
Y
悠
スキップ
オート
セーブ
おわる
'サンプル1.3.2_既に開かれているInternetExplorerを取得する(エラー処理済み)
Public Sub getIE2()
    Dim ie As Object    'IEを格納する変数(オブジェクト型)
    Dim sh As Object    '起動中のShellWindow一式を格納する変数
    Dim win As Object   'ShellWindowを格納する変数
    Dim document_title As String  'ドキュメントタイトルの一時格納変数
    '起動中のShellWindow一式を変数winsに格納
    Set sh = CreateObject("Shell.Application")
    'ShellWindowから1つづつ取得して処理
    For Each win In sh.windows
        'ドキュメントタイトル取得失敗を無視(処理継続)
        On Error Resume Next
        document_title = ""
        document_title = win.Document.Title
        On Error GoTo 0
        'タイトルバーにGoogleが含まれるかチェック
        If InStr(document_title, "Google") > 0 Then
            '変数ieに取得したwinを格納
            Set ie = win
            'ループを抜ける
            Exit For
        End If
    Next
    'URLを表示する
    MsgBox ie.LocationURL
End Sub