使用VBA在默认浏览器中打开html页面? [英] Open an html page in default browser with VBA?

查看:632
本文介绍了使用VBA在默认浏览器中打开html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VBA在默认浏览器中打开HTML页面?我知道这就像:

How do I open an HTML page in the default browser with VBA? I know it's something like:

Shell "http://myHtmlPage.com"

但是我想我必须参考打开页面的程序.

But I think I have to reference the program which will open the page.

推荐答案

您可以使用Windows API函数ShellExecute这样做:

You can use the Windows API function ShellExecute to do so:

Option Explicit

Private Declare Function ShellExecute _
  Lib "shell32.dll" Alias "ShellExecuteA" ( _
  ByVal hWnd As Long, _
  ByVal Operation As String, _
  ByVal Filename As String, _
  Optional ByVal Parameters As String, _
  Optional ByVal Directory As String, _
  Optional ByVal WindowStyle As Long = vbMinimizedFocus _
  ) As Long

Public Sub OpenUrl()

    Dim lSuccess As Long
    lSuccess = ShellExecute(0, "Open", "www.google.com")

End Sub

关于安全性的简短说明:如果URL来自用户输入,请确保严格验证输入为ShellExecute会执行具有用户权限的任何命令,如果用户是用户,则也会执行format c:管理员.

Just a short remark concerning security: If the URL comes from user input make sure to strictly validate that input as ShellExecute would execute any command with the user's permissions, also a format c: would be executed if the user is an administrator.

这篇关于使用VBA在默认浏览器中打开html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆