How do I publish a Excel chart using vba macro?

M

Martin N

I used this vba code in the code module in Excel 2002 (SP3) to publish chart1
created from data on sheet2, but am getting the object define error:

Sub PublishToWeb()

Set oPObjs = ActiveWorkbook.PublishObjects

oPObjs.Add( _
SourceType:=xlSourceChart, _
Filename:="C:\Work.htm", _
Sheet:="Chart1", _
Source:="Chart1", _
HtmlType:=xlHtmlStatic, _
DivID:="Chart1.xls_04").Publish


End Sub

I tried to change the Source and Sheet arguments but it did not help. I
used a similer sub for the sheets and it worked fine:

Sub PublishToWeb()

Set oPObjs = ActiveWorkbook.PublishObjects
oPObjs.Add( _
SourceType:=xlSourceRange, _
Filename:="C:\Work.htm", _
Sheet:="Sheet2", _
Source:="A1:L2", _
HtmlType:=xlHtmlStatic, _
DivID:="Sheet1.xls_04").Publish

End Sub

What am I missing here? Thanks for the help.

Martin.
 
M

Martin N

I recast my statements to something like these and they are now working:

With ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceChart, _
Filename:="C:\Work.htm", Sheet:="Chart1", Source:="Chart 1", _
HtmlType:=xlHtmlStatic, DivID:="Chart1_04")
.Publish (True)
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top