VBScript 将 HTML 导入 Excel 并创建图表
从下面的代码可以看出,我是 VBscripting for Excel 的新手。我只是尝试将 HTML 文件(“DEMO8.HTM”)导入 Excel 并根据 F 列中的数据创建图表。该图表应在创建的工作表中显示为对象。我在使用“Chart.Add”语法时遇到问题。每当我改变它时,就会出现其他问题。不管怎样,这是代码:
Dim chtChart
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\DEMO8.HTM")
objExcel.Visible = TRUE
Set chtChart = Charts.Add
With chtChart
chtChart.ChartType = xlColumnClustered
chtChart.SetSourceData.Range("'DEMO8'!$F:$F")
chtChart.Location.xlLocationAsObject
ActiveChart.SetSourceData Source:=Range("'DEMO8'!$F:$F")
ActiveChart.Legend.Select
Selection.Delete
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlCategory).Select
Selection.Delete
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScale = 300
ActiveChart.Axes(xlValue).MinimumScale = 0
End With
' Give the user control of Excel
UserControl = true
我基本上是通过各种代码来“弗兰肯斯坦”的。它似乎打开了 HTML 文件,但没有创建图表。任何帮助表示赞赏。
As you can tell by the following code, I'm new to VBscripting for Excel. I'm simply trying to import an HTML file ("DEMO8.HTM") into Excel and create a chart based on the data in column F. The chart should show up as an object in the sheet created. I'm having a problem getting the 'Chart.Add' syntax to work. Whenever I change it, something else goes wrong. Anyway, here's the code:
Dim chtChart
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\DEMO8.HTM")
objExcel.Visible = TRUE
Set chtChart = Charts.Add
With chtChart
chtChart.ChartType = xlColumnClustered
chtChart.SetSourceData.Range("'DEMO8'!$F:$F")
chtChart.Location.xlLocationAsObject
ActiveChart.SetSourceData Source:=Range("'DEMO8'!$F:$F")
ActiveChart.Legend.Select
Selection.Delete
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlCategory).Select
Selection.Delete
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScale = 300
ActiveChart.Axes(xlValue).MinimumScale = 0
End With
' Give the user control of Excel
UserControl = true
I basically 'Frankensteined' this from various bits of code. It seems to open the HTML file but doesn't create the chart. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能会让你更接近你想要的;
May get you closer to what you want;
以下代码将 Excel 工作表转换为 html:
The following code will convert excel sheet into html: