【问题标题】:Amending all Charts修改所有图表
【发布时间】:2021-11-02 08:07:51
【问题描述】:

我有一个包含多个工作表的工作簿,每个工作表都有多个图表。

这些都是记录各种功能的进度,所以X轴是日期。

显然,该轴的末尾应该是今天的日期 - 好的,为了视觉效果,比如说今天一周。所以需要每天更换。

Excel 生成了这个宏,效果很好 - 在一张图表上。

    ActiveSheet.ChartObjects("Overall").Activate
    ActiveChart.Axes(xlCategory).Select
    ActiveChart.Axes(xlCategory).MaximumScale = Int(Now()) + 7
    Application.CommandBars("Format Object").Visible = False

如何更改它以使其在每个工作表上执行每个图表?

    Do for each Sheet - how do I do that ?
        Do for each Chart - how do I do that ?
            Do the Biz - code as above, but quotes replaced by what ?
        Loop until what ?
    Loop until what ?

【问题讨论】:

    标签: excel vba charts


    【解决方案1】:
    Option Explicit
    Sub update()
         Dim ws As Worksheet, cht As ChartObject, n As Integer, dt As Date
         dt = Date + 7
         For Each ws In ThisWorkbook.Sheets
              For Each cht In ws.ChartObjects
                  cht.Chart.Axes(xlCategory).MaximumScale = dt
                  n = n + 1
              Next
         Next
         MsgBox n & " charts updated to " & Format(dt, "yyyy-mm-dd"), vbInformation
    End Sub
    

    【讨论】:

    • BR I L - Y U N T !真的非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多