简体   繁体   English

Word中链接的Excel对象的动态范围/范围

[英]Dynamic range for Linked Excel Object/range in Word

I have a Excel Pivot table linked my Word report. 我有一个链接到我的Word报告的Excel Pivot表。 The Pivot table will growth when getting more data. 当获取更多数据时,数据透视表将增长。 However, when the Pivot table size change, it doesn't be reflected in the Word file. 但是,数据透视表的大小更改时,它不会反映在Word文件中。 The word file always display the original selected range. Word文件始终显示原始选定范围。 So I have to update the link range manually. 因此,我必须手动更新链接范围。

Is there is a way to fix this issue or simply the effort? 有什么方法可以解决此问题,还是可以简单地解决问题?

Many thanks. 非常感谢。

Below is my solution to fix this issue. 以下是我解决此问题的解决方案。 1. Create a Named Range for the Pivot Table. 1.为数据透视表创建一个命名范围。 2. Change the Linked Range absolute address in Word file to the Named Range 2.将Word文件中的“链接范围”绝对地址更改为“命名范围”

================ ================

Note for 1: create named range for a Pivot table can be done via Excel "Offset" function. 注意1:可以通过Excel“偏移”功能为数据透视表创建命名范围。 However, the Offset function is not perfect when there are more data in the same sheet. 但是,当同一张纸中有更多数据时,偏移功能并不完美。 so I create my own Excel function to that. 所以我为此创建了自己的Excel函数。

Function PVRange1(Sheet_Name, Pivot_Name) As Range
'Returns a Range object that represents the range containing the entire PivotTable report, but doesn’t include page fields.
'
Dim pvt As PivotTable

Set pvt = Worksheets(Sheet_Name).PivotTables(Pivot_Name)
Set PVRange1 = pvt.TableRange1

End Function


Function PVRange2(Sheet_Name, Pivot_Name) As Range
'Returns a Range object that represents the range containing the entire PivotTable    report, including page fields.

Dim pvt As PivotTable

Set pvt = Worksheets(Sheet_Name).PivotTables(Pivot_Name)
Set PVRange2 = pvt.TableRange2

End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM