vba 如何将 HTML 插入 Excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22223255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:13:46  来源:igfitidea点击:

How to insert a HTML into Excel

htmlexcel-vbagisvbaexcel

提问by yke

I have a map on a website which changes with time (interactive) and I would like to insert it on the excel sheet.

我在网站上有一张随时间变化的地图(交互式),我想将其插入到 Excel 工作表中。

I am using this code but it does not show the HTML:

我正在使用此代码,但它不显示 HTML:

Private Sub Mapit()
URL = Sheets("sheet1").Cells(1, 1) //Here there is written the link to the website that want to show on excel
Sheets("sheet1").Pictures.Insert(URL).Select End Sub

Is that possible? I guess that Sheets("sheet1").Pictures.Insert(URL).Select is the problem but I am not able to find which is the correct way.

那可能吗?我猜是 Sheets("sheet1")。图片.Insert(URL).Select 是问题,但我找不到哪个是正确的方法。

Thank you for your time

感谢您的时间

采纳答案by Santosh

Try this. You are almost there. No need for .Select

尝试这个。你快到了。不需要.Select

Sub Mapit()

    Dim URL As String
    URL = "https://www.google.com/images/srpr/logo9w.png"
    ActiveSheet.Pictures.Insert (URL)

End Sub



Private Sub Mapit()

    Dim URL As String
    URL = Sheets("sheet1").Cells(1, 1)

    ThisWorkbook.Activate
    ThisWorkbook.Sheets("sheet1").Select
    Sheets("sheet1").Pictures.Insert (URL)

End Sub

Updated after comments :

评论后更新:

Insert Userform > Goto toolbox > Additional COntrols > Select Microsoft Web Browser > OK

插入用户表单 > 转到工具箱 > 附加控制 > 选择 Microsoft Web 浏览器 > 确定

Drag the control to userform

拖动控件到用户窗体

Now on userform paste below code

现在在用户表单粘贴下面的代码

Private Sub UserForm_Initialize()
    Me.WebBrowser1.Navigate ("www.google.com")
End Sub