在 Excel 2007 工作表单元格中显示自定义文档属性值
我创建了一个程序,用于在 Excel 2007 工作簿文件中创建并填充自定义文档属性。 但是我无法在工作表单元格中显示此属性的值。 在 Word 2007 中,您只需选择“插入 -> 快速部件 -> 字段...”,然后使用 DocProperty 字段来显示文档中自定义字段的值。 但是我在 Excel 2007 中没有找到类似的函数。
有人知道如何在 Excel 工作表单元格中显示自定义文档属性的值吗? 我更喜欢类似于上面提到的 Word 2007 解决方案的解决方案。 我宁愿不使用宏/自定义代码。
I've created a program that creates and populates a custom document property in an Excel 2007 workbook file. However I haven't been able to show the value of this property in a worksheet cell. In Word 2007 you can just select "Insert -> Quick Parts -> Field..." and use the DocProperty field to show the value of the custom field in a document. However I haven't found a similar function in Excel 2007.
Does anybody know how to display the value of a custom document property in an Excel worksheet cell? I would prefer a solution similar to the Word 2007 solution mentioned above. I rather not use a macro/custom code for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Excel 中的等效方法是通过公式,我认为没有代码就不可能提取文档属性。 没有本地函数来选择文档属性。 (另一种方法是将信息存储在工作簿/工作表名称中,可以通过公式访问)
在 VBA 中,您必须创建一个类似以下的函数:
然后在公式中使用
=CustomProperties("PropertyName" 调用它)
。还有一个微妙的点。 公式依赖性仅与其他单元格相关; 该公式取决于自定义属性。 如果您更新自定义属性,涉及
CustomProperty
的现有公式将不会自动更新。 必须手动重新评估单元格或强制重新计算整个工作簿。 最好的机会是使函数具有易失性,这意味着每次单元格更改时都会重新计算公式 - 但这仍然意味着只有在单元格发生更改时您才会获得更新。The equivalent in Excel would be via formula and I don't think it's possible to extract a document property without code. There are no native functions to pick out document properties. (An alternative could be to store information in workbook/worksheet Names, which ARE accessible via formula)
In VBA you'd have to create a function something like:
and then call it in a formula with
=CustomProperties("PropertyName")
.There is another subtle point. Formula dependencies only relate to other cells; this formula depends on a custom property. If you update the custom property a pre-existing formula involving
CustomProperty
will not be updated automatically. The cell will have to be re-evaluated manually or the entire workbook forced through a recalc. Your best chance would be to make the function volatile, which means the formula would be recalc'd on every cell change -- but this still means you only get an update if a cell has been changed.选择要提取的单元格
将单元格重命名为一些有用的名称。 从“B1”到“Project_Number”。
打开“高级属性”,单击“自定义”选项卡。 输入新属性的名称。 单击“链接到内容”,从“值”下拉列表中选择单元格名称。
我希望我可以接受 cerdit,但我在网上找到了答案:
http://pdmadmin。 com/2012/03/displaying-custom-property-values-in-excel-using-a-named-range/
Select the cell you want to extract
Rename the cell to some useful. From "B1" to "Project_Number".
Open "Advance Properties" click the "Custom" tab. Enter a name for the new property. click "Link to content" the select the cell name from the "Value" pull down list.
I wish i could take cerdit but I found the answer online:
http://pdmadmin.com/2012/03/displaying-custom-property-values-in-excel-using-a-named-range/
您可以将命名范围链接到自定义属性,但自定义属性会反映[范围中的第一个单元格]的值。 它实际上是只读的; 您可以更改单元格的内容来更新属性,但反之则不然。
我知道您想避免它,但如果您想在公式中使用属性值,则必须 创建自定义工作表函数来执行此操作。
You can link a named range to a custom property, but then the custom property reflects the value of the [first cell in the] range. It's effectively read-only; you can change the content of the cell to update the property, but not the other way around.
I know you want to avoid it, but if you want to use the property value in a formula, you'll have to create a custom worksheet function to do so.
我也经历过其他人同样的问题。 因此,我将尝试全面介绍我是如何解决这个问题的。
首先,除了编写一个函数来获取您放入自定义或内置属性中的任何内容并使“问题”单元格以这种方式指向它之外,您别无选择:
PropertyName 是一个引用名称的字符串您希望在单元格中显示其值的自定义/内置属性。
该函数可以编写为(如之前建议的):
对于内置属性,或者:
正如已经提到的,包括 Application.Volatile 将允许半自动单元格内容更新。
然而,这本身就带来了一个问题:每当您打开 Excel 文件时,所有使用这种关系的单元格都会更新,并且当您退出文件时,Excel 会询问您是否允许更新它,无论无论您是否对其进行了任何更改,因为 Excel 本身都做了更改。
在我的开发小组中,我们使用 SubVersion 作为版本控制系统。 如果您在退出时无意中点击了“更新”,SVN 会注意到这一点,并且下次您想要提交更改时,Excel 文件将包含在包中。
所以我决定利用手头的一切去做我需要做的事情,同时避免这种我不想要的自我更新效果。
这意味着将命名范围与属性访问函数结合使用。
鉴于我不能指望旧文件能够满足我的新需求,我编写了这个函数:
它允许正确选择目标单元格。 当为属性分配值时(假设“作者”,它恰好是内置属性),我还会更新存储在命名范围中的值,并且可以在单元格中写入:
如果我碰巧定义了一个范围命名为“Author”,并用内置属性“Author”的值填充其“A1”单元格,我需要对其进行更新以用于我们自己的外部跟踪目的。
这一切都不是一夜之间发生的。 我希望它能有所帮助。
I have experienced the same issues other people have. So I will try to comprehensively cover how I addressed it.
First of all, you have no other option than writing a function meant to get whatever you put in a custom or built-in property and make the "problem" cell to point at it this way:
PropertyName being a string referring to the name of the custom/built-in property whose value you want to be shown in the cell.
The function could be written (as formerly suggested) as:
for a built-in property, or as:
As already mentioned, including Application.Volatile will allow for a semi-automatic cell contents update.
However, this poses a problem on its own: whenever you open your Excel file, all the cells using such a relationship will get updated and, by the time you exit the file, Excel will ask you for your permission to update it, no matter if you did introduce any change on it or not, because Excel itself did.
In my development group, we use SubVersion as a version control system. In case you inadvertently hit "update" on exit, SVN will notice it and next time you want to commit your changes, the excel file will be included in the pack.
So I decided to use everything at hand to do whatever I needed and avoid, at the same time, this self-update effect I didn't want.
That means using named ranges in combination with property accessing function/s.
Given the fact I can't expect old files to have provision for my new needs, I wrote this function:
It allows for a proper selection of the destination cell. When assigning values to a property (let's say "Author", which happens to be a built-in one), I also update the value stored in the named range, and can write in a cell:
if I happen to have defined a range named "Author" and filled its "A1" cell with the value for built-in property "Author", which I need to have updated for our own external tracking purposes.
This all didn't happen overnight. I hope it can be of some help.
我用它来提取 SharePoint 属性(基于 Martin 的答案):
I used this for extracting the SharePoint properties (based on Martin's answer):
不幸的是,我相信您需要使用用户定义的函数。 将新的 VBA 模块添加到您的工作簿并添加此函数:
对
Application.Volatile
的调用强制单元格在每次重新计算时更新,确保它将获取文档属性中的更改。Unfortunately I believe you need to use an user defined function. Add a new VBA module to your workbook and add this function:
The call to
Application.Volatile
forces the cell to be updated on each recalculation ensuring that it will pick up changes in the document properties.