问题
I am trying to publish an Excel Chart automatically every minute using a VBA code.
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". Does anybody know what is happening?
回答1:
.Publish is a sub, not a function so you'll need to take away the parenthesis around the True.
回答2:
I'm not sure without seeing your spreadsheet, but you will get "Application-defined or object-defined error" if "Chart1" is a worksheet. 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.
来源:https://stackoverflow.com/questions/8346707/how-to-automatically-publish-a-html-chart-in-excel-using-a-vba-macro