「なるほど。このサンプルコードは今後このまま使いまわせそうだな……」
'ドキュメントタイトル/URLを指定してIEを取得
Public Function
getIE(arg_title As String, Optional arg_url As String) As Object
Dim ie As Object 'IEを格納する変数(オブジェクト型)
Dim sh As Object '起動中のShellWindow一式を格納する変数
Dim win As Object 'ShellWindowを格納する変数
Dim document_title As
String 'ドキュメントタイトルの一時格納変数
Set sh =
CreateObject("Shell.Application") 'ShellWindowをwinsに格納
'ShellWindowから1つづつ取得して処理
For Each win In
sh.windows
'ドキュメントタイトル取得失敗を無視(処理継続)
On
Error Resume Next
document_title = ""
document_title = win.document.Title
On
Error GoTo 0
'タイトルバーに引数が含まれるかチェック
If
InStr(document_title, arg_title) > 0 Then
Set ie = win '変数ieに取得したwinを格納
Exit For 'ループを抜ける
End
If
Next
'見つからなかった場合 かつ URLが指定されている場合は起動する
If ie Is Nothing And arg_url <>
"" Then
Set
ie = CreateObject("InternetExplorer.Application")
ie.Navigate2
(arg_url)
ie.Visible = True
End If
Set getIE = ie '値の返却
End Function