如何将焦点带到msgbox?

时间:2013-09-16 16:30:17

标签: vba excel-vba excel

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

以上是我的代码。我试图将msgbox带到前面,但我无法让AppActivate这样做。

当我离开AppActivate(“Checker”)时,我得到: 运行时错误'5': 无效的过程调用参数,帮忙?

1 个答案:

答案 0 :(得分:4)

试试这个:

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