How to Display MessageBox in Front of IE Browser

このQ&Aのポイント
  • Learn how to display a MessageBox in front of an IE browser window using vbApplicationModal.
  • If you want to show a MessageBox in front of an IE browser window instead of behind it, you can use the vbApplicationModal option when calling the MsgBox function.
  • By adding the vbApplicationModal option, the MessageBox will be displayed in front of the browser window, allowing the user to interact with it.
回答を見る
  • ベストアンサー

IEブラウザよりmsgboxを手前に表示したい

当方 IE9+2007です。 Sub yahoo() Dim objIE As Object Dim i As Long Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate "http://www.yahoo.co.jp/" Do Until objIE.Busy = False And objIE.ReadyState = 4: Loop If objIE.Document.Body.innerHTML Like "*こんにちは、*さん*" Then i = MsgBox("別のIDでログインしています!続けますか?", vbYesNo + vbApplicationModal) If i = 7 Then End End If End Sub このような事がやりたいのですが、 IEブラウザを立ち上げてメッセージボックスをvbApplicationModalで表示させても ブラウザより裏側で表示されてしまいます。 If objIE.Document.Body.innerHTML Like "*こんにちは、*さん*" Then i = MsgBox("別のIDでログインしています!続けますか?", vbYesNo + vbApplicationModal) If i = 7 Then End End If objIE.Visible = True という順番にすればよいのですが、他のコードの関係もあってメッセージボックスより先にブラウザを表示させたいのです。 そんな事は可能でしょうか? ご回答よろしくお願いします。

質問者が選んだベストアンサー

  • ベストアンサー
  • ki-aaa
  • ベストアンサー率49% (105/213)
回答No.2

こんにちわ。 あちこちのサイトからの寄せ集めです。 Option Explicit Public Declare Function MessageBox Lib "user32.dll" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long Public Const MB_OK = &H0 'OKボタン Public Const MB_TOPMOST = &H40000 '最前面フラグ Public Const MB_YesNo = 4 'はい いいえ Public Const MB_DefaultButton2 = 256 sub test . lpText = "別のIDでログインしています!続けますか" lpCaption = "最前面Msgbox" If MessageBox(0, lpText, lpCaption, MB_YesNo Or MB_DefaultButton2 Or MB_TOPMOST) = vbYes Then 'データの処理 End If

xmwksmyick2
質問者

お礼

ありがとうございました。

その他の回答 (1)

  • xls88
  • ベストアンサー率56% (669/1189)
回答No.1

例えばExcel VBAということならMsgboxの前にAppActivateすれば希望が叶うと思います。 AppActivate Application.Caption If objIE.Document.Body.innerHTML Like "*こんにちは、*さん*" Then i = MsgBox("別のIDでログインしています!続けますか?", vbYesNo)

xmwksmyick2
質問者

お礼

AppActivate Application.Caption を追加してみましたが エラーにはなりませんでしたが やはりブラウザの後ろで表示されてしまいます

関連するQ&A

  • VBAからIEの操作

    グーグルをIEで開いてVBA(語句)を検索して見終わったら IEを閉じる作業をしたいのですが、検索窓にVBA(語句)を 入力するところでエラーとなります。初心者ですが、なんとか 勉強したいのでよろしくお願いいたします。 Sub ie_test_Navigate() Dim objIE As Object Set objIE = CreateObject("InternetExplorer.application") objIE.Visible = True objIE.Navigate "http://www.google.co.jp/" IE.document.all.q.Value = "VBA" IE.document.all.btnG.Click If MsgBox("IEを閉じますか?", vbYesNo, "終了確認") = vbYes Then objIE.Quit End If Set objIE = Nothing End Sub

  • 三菱東京UFJ銀行に自動ログインしたいのですが

    どうもうまくできません。 ログインボタンが押せません。 Sub tset() Dim objIE As Object Dim i As Long Set objIE = CreateObject("InternetExplorer.Application") objIE.navigate "https://entry11.bk.mufg.jp/ibg/dfw/APLIN/loginib/login?_TRANID=AA000_001" objIE.Visible = True Do While objIE.Busy = True DoEvents Loop With objIE.document .all("KEIYAKU_NO").Value = "test" .all("PASSWORD").Value = "PASSWORD" End With For i = 0 To objIE.document.Links.Length - 1 If objIE.document.Links(i).innerHTML Like "*alt=ログイン*" Then objIE.document.Links(i).Click Exit For End If Next i For i = 0 To objIE.document.Links.Length - 1 If objIE.document.Links(i).innerText = "ログイン" Then objIE.document.Links(i).Click Exit For End If Next i End Sub でも、押せないのですが、ご教授いただけませんか? よろしくお願いします。

  • vba ie操作 電気家計簿ログインできない

    いつもお世話になっております。 何度も質問して申し訳ございません。またまた教えてください。 電気家計簿(https://www.kakeibo.tepco.co.jp/dk/aut/login/)のログインボタンをVBAで押したいのですが うまくできません。 コードは下記の通りです。 ***************************************************************** Sub test() Dim objIE As InternetExplorer Dim myObj As Object Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate "https://www.kakeibo.tepco.co.jp/dk/aut/login/" Do While objIE.Busy = True Or objIE.ReadyState <> 4 DoEvents Loop objIE.Document.all("id").Value = "test" objIE.Document.all("password").Value = "tset" 'objIE.Document.Forms(0).submit 'これだと更新されちゃうっぽい 'objIE.Document.Forms(0).Item(2).Click 'Item(0)とItem(1)はエラーにならないけど何も起こらない。Item(2)にするとエラー 'objIE.Document.all.submit.Click 'エラー 'エラーにならないけど何も起こらない 'For i = 0 To objIE.Document.Links.Length - 1 ' If objIE.Document.Links(i).innerHTML Like "*alt=ログイン*" Then ' objIE.Document.Links(i).Click ' Exit For ' End If 'Next i 'エラーにならないけど何も起こらない 'For Each myObj In objIE.Document.forms(0).all ' If TypeName(myObj) = "HTMLInputElement" Then ' If myObj.alt = "ログイン" Then ' myObj.Click ' Exit For ' End If ' End If 'Next Set objIE = Nothing End Sub ***************************************************************** 自分なりにいくつか試してみたのですが、うまくいきませんでした。 ご教授よろしくお願いします。

  • IEを探すプログラムがうまくいきません。

    VBScriptで指定するサイトが開いていなかった場合とある処理を行い、とあるサイトが開いていれば別の処理をし終了させることをやっていますがうまくいきません。 自分の考えとしては 1・開いているIEをくるくるループ回して探す 2・その中にヤフーがあればフラグをTrue処理   それ以外はFalse処理 これだけで終わりにしたいのですが・・・ Dim objIE Dim objShell Dim objWindow Dim WinExist Dim strURL Dim Flug Dim strURL2 strURL = "http://www.yahoo.co.jp/" strURL2 = "http://www.google.co.jp/" 'IEが起動して無い場合プログラムが起動しないのでダミー立ち上げ Set objIE = WScript.CreateObject("InternetExplorer.Application") objIE.Navigate "about:blank" objIE.Visible = True Set objIE = Nothing WinExist = False Set objShell = CreateObject("Shell.Application") For Each objWindow In objShell.Windows If TypeName(objWindow.Document) = "HTMLDocument" Then WinExist = True Set objIE = objWindow End If Next If objIE.LocationURL = strURL Then Flug = True Else If objIE.LocationURL <> strURL Then Flug = False Else WScript.sleep(1) End If If Flug = False Then Set objIE = WScript.CreateObject("InternetExplorer.Application") objIE.Navigate strURL2 objIE.Visible = True Set objIE = Nothing End If ' 'いろいろな処理があるが省く ' If Flug = True Then msgbox "ヤフー存在" End If End If 絶対にフラグがTrueになることがありません。 Excelでデバッグしてみましたがなぜうまくいかないのかが理解できておりません。 自分としては開いているIEをぐるぐるとまず回ってヤフーが開いていればTrue時の処理を行い終了、 なければFalse時の処理を行うという風にしたいです(無限ループではありませんでした) For eachを使っているので途中でIf Flug以降の処理を行ってしまうのも無駄な繰り返しで困ってしまいます。 そこでフラグを立てることを考えたのですがどうも思うようにいきません。 ボキャブラリが足りませんが、いい知恵を貸していただけないでょうか?

  • vba ie操作 ログインしたい

    いつもお世話になっております。 前回ご回答いただいた方ありがとうございました。 またまた困ったことにログインしたいサイトがあるのですがうまくできません。 URLはhttps://www.a-q-f.com/openpc/USB0100S01Action.do?aqf_id=S0000&send_url=https://www.a-q-f.com/&get_userInfo=&r=2941249539317530063 なのですが、ログインが二つあり、左側でログインしたいのですが、ボタンを押下できません。 **************************************************** Sub 永久不滅ドットコム() Dim objIE As InternetExplorer Set objIE = CreateObject("InternetExplorer.application") objIE.Visible = True objIE.Navigate "https://www.a-q-f.com/openpc/USB0100S01Action.do?aqf_id=S0000&send_url=https://www.a-q-f.com/&get_userInfo=&r=2941249539317530063" Do While objIE.Busy = True Or objIE.ReadyState <> 4 DoEvents Loop objIE.Document.all.ID.Value = "test" objIE.Document.all.idPassword.Value = "test" Do While objIE.Busy = True Or objIE.ReadyState <> 4 DoEvents Loop For i = 0 To objIE.Document.Links.Length - 1 If objIE.Document.Links(i).innerHTML Like "*alt=ログイン*" Then '何も起こらない objIE.Document.Links(i).Click Exit For End If Next i objIE.Document.Forms(0).Click '何も起こらない objIE.Document.Forms(0).Submit 'エラーになる Set objIE = Nothing End Sub **************************************************** をやってみましたが無理でした・・・ ご教授よろしくお願いします。

  • VBでのContinueが間違っているとき

    http://oshiete1.goo.ne.jp/qa4564345.htmlではありがとうございました。 教わったことを参考にやってみたのですがうまくいきません。 Continueの部分がうまくいくPCといかないPCがあるのでどうしたらいいか分からなくなってしまいました・・・ Option Explicit Dim objIE Dim objShell Dim objWindow Dim WinExist Dim strURL Dim strURL2 Dim Flug strURL = "http://www.yahoo.co.jp/" strURL2 = "http://www.google.co.jp/" WinExist = False Set objShell = CreateObject("Shell.Application") For Each objWindow In objShell.Windows If TypeName(objWindow.Document) <> "HTMLDocument" Then Continue End If WinExist = True Set objIE = objWindow If objIE.LocationURL = strURL Then Flug = True Exit For End If Next If Flug = True Then msgbox "ヤフー存在" Else msgbox "別の処理を行なう" If WinExist = False Then 'IEが無い場合 起動する Set objIE = WScript.CreateObject("InternetExplorer.Application") objIE.Navigate strURL2 objIE.Visible = True Set objIE = Nothing End If End If

  • vbaでnanacoにログイン(ie操作)

    私は「緑のパスワードがなくnanacoをお持ちの方」です。 カード記載の番号にはvbaで値を入れることはできるのですが、 nanaco番号に値を入れることとログインボタンを押すことができません。 ********************************************** Sub nanaco() Dim objIE As InternetExplorer Dim myObj As Object Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.navigate "https://www.nanaco-net.jp/pc/emServlet" Do While objIE.Busy = True DoEvents Loop Do While objIE.document.readyState <> "complete" DoEvents Loop objIE.document.all("XCID").Value = "12345" objIE.document.all("SECURITY_CD").Value = "Password" For Each myObj In objIE.document.forms(0).all If TypeName(myObj) = "HTMLInputElement" Then If myObj.alt = "ログイン" Then myObj.Click Exit For End If End If Next Set objIE = Nothing End Sub ********************************************** これだとまずall("XCID").Value でエラーになります。 ソースでは、 <input name="XCID" tabIndex="1" class="txtBoxLogin" accessKey="1" type="text" maxLength="16" value=""/> となっておりますが、同じコードが二つあるからエラーになるのでしょうか? all("SECURITY_CD").Value は問題なくできます。 ソースにも、SECURITY_CDは一つしかないです。 次にログインボタンも二つあるのですが、 For Each myObj In objIE.document.forms(0).all If TypeName(myObj) = "HTMLInputElement" Then If myObj.alt = "ログイン" Then myObj.Click Exit For End If End If Next このコードを実行すると、多分上の方のログインボタンが押されてるようです。 なので、 Dim 二つ目 As Boolean For Each myObj In objIE.document.forms(0).all If TypeName(myObj) = "HTMLInputElement" Then If myObj.alt = "ログイン" Then If 二つ目 = True Then myObj.Click Exit For End If 二つ目 = True End If End If Next に変更してみたのですが、 どうやら If myObj.alt = "ログイン" Then になるのは、1回しかないようです。 うーん、うまくできません。 ご教授よろしくお願いします。

  • NewはCreateObjectと同じ意味?

    Sub test01() Dim objIE As InternetExplorer Set objIE = CreateObject("InternetExplorer.application") objIE.Visible = True End Sub Sub test02() Dim objIE As New InternetExplorer objIE.Visible = True End Sub この二つのコードを比較した場合、 Dim objIE As New InternetExplorer で宣言すれば、 Set objIE = CreateObject("InternetExplorer.application") がなくても、 objIE.Visible = True をしてみるとブラウザが立ち上がっているのですが、 これは NewはCreateObjectと同じ意味という事でしょうか?

  • 起動しているIEをVBSで閉じるときの問題・・・

    VBスクリプトで起動しているIEを探し特定のサイトであればウィンドウを閉じたいのですがどのようにすればよいのでしょうか? Dim ObjIE Dim ObjShell Dim ObjWindow Dim WinExist WinExist = False Set ObjShell = CreateObject("Shell.Application") For Each ObjWindow In ObjShell.Windows If TypeName(ObjWindow.Document) = "HTMLDocument" Then WinExist = True Set ObjIE = ObjWindow End If Next Set ObjShell = Nothing If Not WinExist = True Then Set ObjIE = CreateObject("InternetExplorer.Application") End If If objIE.Document.URL = "http://www.yahoo.co.jp/" Then objIE.quit End If If objIE.Document.URL = "http://www.excite.co.jp/" Then objIE.quit End If If objIE.Document.URL = "http://www.google.co.jp/" Then ?????????? End If ・ ・ ・ 例えばディスプレイ上にYahoo、Excite、Googleのホームページがそれぞれ立ち上がっていたとします。 もしYahooがあれば閉じて次にExciteを探しあれば閉じて、次にGoogleのページがあればそのままにし後の処理を行わず終わらせたいのですが・・・もしGoogleが開いていればこれ以降の処理を全てすっ飛ばして終了にしたいのですが・・・ また、If thenを繰り返してばかりで汚いコードのような気もします。 これをやっていてYahoo、Excite、Google全て開いていた場合何故かエラーが出て終了してしまいます。 どなたかいい方法があれば教えて下さい。

  • VBAで、デバッグをお願いします。

    作りたいプログラムはpartsno_01から、partsno_20までのテキストボックスに、エクセルのセルA1から、A20までにある製品番号を入力し、データをsubmitするものです。 Sub pn() Dim ObjIE As Object Dim ObjShell As Object Dim ObjWindow As Object Dim WinExist As Boolean WinExist = False Set ObjShell = CreateObject("Shell.Application") For Each ObjWindow In ObjShell.Windows If TypeName(ObjWindow.document) = "HTMLDocument" Then WinExist = True Set ObjIE = ObjWindow End If Next Set ObjShell = Nothing If Not WinExist = True Then MsgBox "製品番号検索を開いてください。" Exit Sub End If ObjIE.Visible = True Do While i < 21 i = 1 Set elements = ObjIE.document.getElementsByName("partsno_0" & "i") If elements Is Nothing Then Exit Sub End If elements.Item(0).Value = Worksheets(1).Cells(i, 1).Value i = i + 1 Loop End Sub で、 elements.Item(0).Value = Worksheets(1).Cells(1, 1).Value が常にエラーになります。 間違っていはいないと思うんですが・・・・。 何がいけないのでしょうか。

専門家に質問してみよう