2
Private Sub CommandButton1_Click()
Dim i As Long
Dim xreply As Integer
Dim names As Long

Dim IE As Object

i = ActiveSheet.Range("D1").Value

While Not IsEmpty(ActiveSheet.Range("A" & i).Value)

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "WEBSITENAME" & ActiveSheet.Range("A" & i).Value 

'wait for webpage to load
Do
    DoEvents
Loop Until IE.READYSTATE = 4

'pagedown to the info
Application.SendKeys "{PGDN}", True
Application.SendKeys "{PGDN}", True

xreply = MsgBox("Is this page for women? Record:" & i, vbYesNo, "Checker")
Application.Visible = True
AppActivate ("Checker")

If xreply = vbYes Then
    ActiveSheet.Range("B" & i).Value = "Yes"
    Else
    ActiveSheet.Range("B" & i).Value = "No"
End If

'quit IE
IE.Quit
i = i + 1
ActiveSheet.Range("D1").Value = i
Wend

End Sub

Above is my code. I am trying to bring the msgbox to the front, yet I can not get AppActivate to do so.

When I leave AppActivate("Checker") I get: Run-Time error '5': Invalid procedure call argument, help?

Community
  • 1
  • 1
Michaeljwjr
  • 423
  • 4
  • 7
  • 13
  • You can't interact with the message box till the time it is disposed so any line after `xreply = MsgBox("Is this page for women? Record:" & i, vbYesNo, "Checker")` will not run till the time the messagebox is disposed. One alternative is to create and show modeless userforms and then you will be able to achieve what you want. – Siddharth Rout Sep 16 '13 at 16:41
  • Another way to think about this is that the `MsgBox` command waits until it is complete to continue code execution. That is, until your user selects yes or no, the next line of code will not be executed. – enderland Sep 16 '13 at 17:21
  • I am guessing this is some odd interaction issue between IE and Excel. Set Excel to the active application, etc, before the msgbox. That should resolve your trouble. – Alan Waage Sep 16 '13 at 17:41
  • The parent of the messagebox is the excel application so bring that to the front and then display your messagebox. This should achieve the desired results. As it sits now it looks like the instance of IE is the window in focus. – Sorceri Sep 16 '13 at 18:04
  • How do I bring AppActivate Excel? Put the title of the excel window in the AppActivate command? – Michaeljwjr Sep 16 '13 at 18:19

1 Answers1

5

Try this:

...
AppActivate ("Microsoft excel")
xreply = MsgBox("Is this page for women? Record:" & i, vbYesNo, "Checker")
...
Dmitry
  • 421
  • 4
  • 14