简体   繁体   English

如何使用VBA宏在Excel中自动发布HTML图表?

[英]How to automatically publish a HTML Chart in Excel using a VBA Macro?

I am trying to publish an Excel Chart automatically every minute using a VBA code. 我试图使用VBA代码每分钟自动发布一个Excel图表。

Sub Auto_Open()
ActiveWorkbook.PublishObjects.Add(xlSourceChart, _
 "C:\Users\file\graph.html" _
 , "Chart1", "", xlHtmlStatic, "DevXSample_16365", _
 "Graph1").Publish (True)
Application.OnTime Now + TimeValue("00:01:00"), _
 "Auto_Open"
End Sub

I've grab this code in a website but when I run it Excel displays this error message: "Application-defined or object-defined error". 我在网站上获取此代码但是当我运行它时,Excel会显示以下错误消息:“应用程序定义的或对象定义的错误”。 Does anybody know what is happening? 有人知道发生了什么吗?

.Publish是一个sub,而不是一个函数,因此你需要取消True周围的括号。

I'm not sure without seeing your spreadsheet, but you will get "Application-defined or object-defined error" if "Chart1" is a worksheet. 我不确定没有看到你的电子表格,但如果“Chart1”是一个工作表,你将得到“应用程序定义或对象定义的错误”。 If your source is xlSourceChart , then Chart1 must be a chart type (created by clicking on a tab and choosing Insert/Chart) not a worksheet type. 如果您的源是xlSourceChart ,则Chart1必须是图表类型(通过单击选项卡并选择“插入/图表”创建)而不是工作表类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM