关闭Word文档的ChartData窗口

问题描述 投票:1回答:1

我有代码打开Word文档并浏览图表,更新数据。

问题是我连续多次调用这个宏。即使我关闭Word应用程序,图表数据窗口仍保持打开状态。

Excel崩溃而没有告诉我为什么,但E认为问题是图表数据窗口没有关闭。因为如果我只运行一次宏,它就可以了。

但是,如果图表不支持此属性,如何关闭chartdata窗口?

Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdShape As InlineShape
Dim wdChart As Word.Chart

Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True

'Opening the document
Set wdDoc = wdApp.Documents.Open("path_here")

'Opening the chartdata window
Set wdShape = wdDoc.InlineShapes(1)
Set wdChart = wdShape.Chart
wdChart.ChartData.Activate

'Changing the data
Range("B2").Value = 120
Range("B3").Value = 155

'Closing the app
wdApp.Quit SaveChanges:=wdSaveChanges

Set wdShape = Nothing
Set wdChart = Nothing
Set wdApp = Nothing
Set wdDoc = Nothing
excel vba ms-word
1个回答
1
投票

此代码将更改数据中的值,而不激活chartdata窗口。由于某种原因,wdChart变量抛出了一个常量赋值错误,因此我将其更改为wdCh。

Set wdShape = wdDoc.InlineShapes(1)
Set wdCh = wdShape.Chart
With wdCh.ChartData.Workbook.Sheets(1)
   .Range("B2").Value = 120
   .Range("B3").Value = 155
End With
© www.soinside.com 2019 - 2024. All rights reserved.