admin管理员组

文章数量:1535046

VBA调用浏览器打开指定网页的几种方法

下面的几段VBA代码都可以打开浏览器并打开指定的网页:

方法一:用API打开默认的浏览器

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub OpenWebPage1()

ShellExecute 0&, vbNullString, "http://www.doczj/doc/f9c42ac777232f60dccca141.html", vbNullString, vbNullString, vbNormalFocus

End Sub

方法二:用“FollowHyperlink”方法:

Sub OpenWebPage2()

ActiveWorkbook.FollowHyperlink

Address:="http://www.doczj/doc/f9c42ac777232f60dccca141.html", NewWindow:=True

End Sub

注意网址中要包含“http://”。

方法三:用“InternetExplorer”对象

Sub OpenWebPage3()

Dim IE As Object

Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True

IE.Navigate ("http://www.doczj/doc/f9c42ac777232f60dccca141.html")

End Sub

方法四:用Shell语句

这个方法可以用指定的浏览器打开某个网页。例如调用IE打开网址“http://www.doczj/doc/f9c42ac777232f60dccca141.html”

Sub OpenWebPage4()

Dim url As String

url = "http://www.doczj/doc/f9c42ac777232f60dccca141.html"

本文标签: 几种方法浏览器文件网页VBA