源代码如下
Option ExplicitPrivate WithEvents wb As WebBrowser
Private WithEvents doc As HTMLDocumentPrivate Sub Command1_Click()
MsgBox doc.body.innerHTML
End Sub'单击这个按钮时报错,Method 'Navigate2' of object 'IWebBrowser2' failed
Private Sub Command2_Click()
wb.Navigate2 "http://www.baidu.com"
End SubPrivate Sub Form_Load()
Set wb = New WebBrowser
wb.Visible = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
If Not wb Is Nothing Then wb.Quit
Set wb = Nothing
End SubPrivate Sub wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = wb.document
End SubPrivate Sub wb_OnQuit()
If wb.Busy Then wb.Stop
Set wb = Nothing
End Sub
如果可以的话,上面这段代码应该怎么改呢?
Option ExplicitPrivate WithEvents wb As WebBrowser
Private WithEvents doc As HTMLDocumentPrivate Sub Command1_Click()
MsgBox doc.body.innerHTML
End Sub'单击这个按钮时报错,Method 'Navigate2' of object 'IWebBrowser2' failed
Private Sub Command2_Click()
wb.Navigate2 "http://www.baidu.com"
End SubPrivate Sub Form_Load()
Set wb = New WebBrowser
wb.Visible = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
If Not wb Is Nothing Then wb.Quit
Set wb = Nothing
End SubPrivate Sub wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = wb.document
End SubPrivate Sub wb_OnQuit()
If wb.Busy Then wb.Stop
Set wb = Nothing
End Sub
如果可以的话,上面这段代码应该怎么改呢?
解决方案 »
- 求高手解决:有关VB中.exe 文件的问题
- ImgAdmin控件删除一页图片出错
- 菜鸟问 如何科学管理各个窗口的打开与关闭
- 我的菜单项的行高为什么比人家的菜单项行高小啊?
- gettickcount 小于0问题
- ▲▲▲▲▲▲▲我是菜鸟,刚学VB,请问怎么用VB写CLASS啊??
- 在VB中的LISTVIEW控件如何右键单击项目时出现右键菜单,像资源管理器中右键单击文件或目录时出现的那样
- 怎样知道软驱或者光驱里没有磁盘??
- 提问:关于文本框的输入
- ????如何用mshflexgrid+text 控件实现表单输入??????
- vb socket鎺ュ彈鍥剧墖
- COM在VB6.0上使用的问题VS选择比尔.盖次的痛苦....
Private WithEvents doc As HTMLDocumentPrivate Sub Command1_Click()
MsgBox doc.body.innerHTML
End SubPrivate Sub Command2_Click()
wb.Navigate2 "http://www.baidu.com"
End SubPrivate Sub Form_Load()
Set wb = New InternetExplorer
wb.Visible = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
If Not wb Is Nothing Then wb.ExecWB OLECMDID_CLOSE, OLECMDEXECOPT_DONTPROMPTUSER
Set wb = Nothing
End SubPrivate Sub wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = wb.document
End Sub
这样写,语法上是没有问题的,但是对于WebBrowser而言,它仍然不知道它的顶级窗口是什么,所以,有关接口的初始化会失败,导致调用Navigate2方法出现错误另外,如果只是想不出现界面的话,用我上面的代码,把:
wb.Visible = True
注释掉即可