我正在尝试将图表从excel发布到HTML文件,我希望在自动Outlook邮件中进一步使用。 下面是代码:
Sub SaveChartWeb()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = ActiveSheet
wb.PublishObjects.Add _
SourceType:=xlSourceChart, _
Filename:=wb.Path & "\Sample2.htm", _
Sheet:=ws.Name, _
Source:="Chart 22", _
HtmlType:=xlHtmlChart
wb.PublishObjects(1).Publish (True)
End Sub
当我运行此代码时,它会抛出以下错误: “运行时间1004:此版本在excel上不再支持此方法或属性”
我尝试过sourcetype和HTMLtype的所有可能组合。当我使用xlHTMLstatic时,它可以工作,但它会发布整个工作表,这是不可取的。
答案 0 :(得分:0)
继续我的评论,试试这个
Sub SaveChartWeb()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
ws.ChartObjects("Chart 1").Activate
ActiveChart.Location Where:=xlLocationAsNewSheet
With wb.PublishObjects.Add(xlSourceChart, "C:\Sample.htm", ActiveChart.Name _
, "", xlHtmlStatic, "", "")
.Publish (True)
End With
End Sub
您始终可以将图表移回工作表或关闭原始文件而不保存。