自我更新Excel / VBA仪表板,循环显示图形

时间:2018-08-01 06:33:12

标签: excel vba excel-vba

我有一台壁挂式PC,安装了Office,屏幕上应该显示几个图表,这些图表在5分钟的间隔内循环显示并刷新。

在同一文件夹中,我创建了一个运行在路透社每天向其转储数据的服务器上的电子表格,以及一个“仪表板”电子表格。

我将仪表板中的工作表链接到数据导入工作簿以同步数据并运行以下VBA代码。

Sub UpdateEverything()

    startTime = Now
    Workbooks("Dashboard").RefreshAll
    Application.OnTime Now + TimeValue("00:05:00"), "UpdateEverything"
    Debug.Print "I'm still running at " & Now & " and I started at " & startTime

End Sub

问题: -有更好的方法吗?

  • 如何循环浏览包含全屏图表的工作表?
  • 如何显示全屏图形,而不仅仅是最大化的excel窗口

谢谢

1 个答案:

答案 0 :(得分:0)

我找到了一种方法,这种方法比较平滑,但也许不是最好的方法。

  • 不允许平滑中断循环。

  • 更新有时会有点慢


Sub UpdateEverything()

    'sets the start and wait time
    startTime = Now
    updateTime = "00:00:10"
    l = 0

    Do While True
        'update counter
        l = l + 1

        'refresh
        Workbooks("Dashboard").RefreshAll
        Debug.Print "I was still running at " & Now & " and I started at " & startTime
        Debug.Print "loop #" & l & " and i #" & i

        For Each c In Charts

            'show next graph
            c.Activate
            'wait a bit
            Application.Wait Now + TimeValue(updateTime)

        Next

    Loop

End Sub