方法一:用API打开默认的浏览器
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ...
下面的几段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, "www.zhixing123.cn", vbNullString, vbNullString, vbNormalFocus
End Sub
方法二:用“FollowHyperlink”方法:
Sub OpenWebPage2()
ActiveWorkbook.FollowHyperlink Address:="http://www.excel123.cn", NewWindow:=True
End Sub
注意网址中要包含“http://”。
方法三:用“InternetExplorer”对象
excel用VBA选择工作表中所有包含超链接的单元格
要选择工作表中所有包含超链接的单元格,用定位或查找的方法无法实现。下面的VBA代码可以实现这一目的。 按Alt F11,打开VBA编辑器,在“工程”窗口中双击某个工作表,在右侧的代码窗口中输入下列代码: Sub SelectHyperlinkCells()Dim hHlink As Hyperl
Sub OpenWebPage3()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate ("www.excel123.cn")
End Sub
方法四:用Shell语句
这个方法可以用指定的浏览器打开某个网页。例如调用IE打开网址“www.zhixing123.cn”
Sub OpenWebPage4()
Dim url As String
url = "www.excel123.cn"
Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE " & url, vbNormalFocus
End Sub
说明:
1.将“C:\Program Files\Internet Explorer\IEXPLORE.EXE ”换成其他浏览器程序,则可用指定的浏览器打开网页。例如系统中已安装遨游浏览器(Maxthon),并安装在“C:\Maxthon2”文件夹中,将上述语句更改为“C:\Maxthon2\Maxthon.exe ”将用Maxthon打开指定的网页。
2.注意“C:\Program Files\Internet Explorer\IEXPLORE.EXE ”的结尾处有一空格。如果忽略此空格,Excel将出现错误提示“文件未找到”。
Excel VBA中debug.print解释和使用介绍
VBA 中Debug.Print 是什么意思? debug.print的使用方法是怎样的呢? VBA 中Debug.Print 的作用是将代码执行结果显示在“立即窗口”中。 比如,我们按ALT F11组合键,打开VBE窗口,插入——模块,输入下面的代码: Sub 测试