使用xlHTML属性将图表从Excel发布到HTML时出现问题 [英] Issue while publishing chart from excel to HTML using the xlHTML properties

查看:26
本文介绍了使用xlHTML属性将图表从Excel发布到HTML时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图表从excel发布到HTML文件,希望在自动Outlook邮件中进一步使用.下面是代码:

I am trying to publish chart from excel to HTML file which I wish to further use in automated outlook mail. below is the code:

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上不再支持此方法或属性"

when I run this code it throws the following errors: "Run time 1004: This method or property is no longer supported in this version on excel"

我尝试了所有可能的sourcetype和HTMLtype组合.当我使用xlHTMLstatic时,它可以工作,但是会发布整个工作表,这是不希望的.

I have tried all the possible combination of sourcetype and HTMLtype. when I use xlHTMLstatic it works but it publishes the entire sheet, which is not desired.

推荐答案

在我的评论中,尝试此操作

Further to my comments, try this

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

您始终可以将图表移回工作表或关闭原始文件而不保存.

You can always move the chart back to the sheet or close the original file without saving.

这篇关于使用xlHTML属性将图表从Excel发布到HTML时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆