vba - Set user-defined cell value in Visio document shape sheet from a macro.
问题描述
I added a row to the User-defined Cells section of the main Visio document shape sheet called User.Revision. I can use the value in the drawings by adding a field set to use a Custom Formula =TheDoc!User.Revision.
I would like to have a macro to set this Cell value but I can't find a way to reference the User-defined Cells in VBA. TheDoc!User.Revision doesn't work.
解决方案
所以这有点晚了,但我想有人可能仍然可以使用它。
ShapeSheet
文档的 被调用并且DocumentSheet
可以像这样访问:
Sub testReadWriteDocumentSheet()
Dim someDoc As Visio.Document
Set someDoc = ThisDocument 'or whatever other document you need
Dim rowName As String 'the Name of the Row
rowName = "ExampleRevision"
Dim value As String 'the value you want to store, change to whatever format you need.
value = "132ABC"
'to set up the cell:
PrepareCellOnDocumentSheet someDoc, rowName
'to write
someDoc.DocumentSheet.CellsU("User." & rowName).FormulaForceU = Chr$(34) & value & Chr$(34)
'Chr$(34) is needed to add the quotes if you store a string,
'if you store a Double or Long leave them out.
'to read:
Dim returnValue As String
returnValue = someDoc.DocumentSheet.CellsU("User." & rowName).ResultStr(visNoCast)
'returns the string but without the quotes
Debug.Print returnValue
End Sub
奖励:此代码自动检查您要求的行(和用户部分)是否存在,如果不存在则添加它们。
Private Function PrepareCellOnDocumentSheet(ByVal someDoc as Visio.Document, ByVal rowName As String)
With someDoc.DocumentSheet
If Not .SectionExists(visSectionUser, False) Then
.AddSection visSectionUser
End If
If Not .CellExistsU("User." & rowName, True) Then
.AddNamedRow visSectionUser, rowName, visTagDefault
End If
End With
End Function
推荐阅读
- bash - 我正在尝试编写一个显示 10 个不同随机数的 bash 脚本,到目前为止,我拥有的一些数字是重复的
- php - 将 MySql 查询的 JSON_KEYS(specs) 结果转换为 php 数组?
- swift - Algolia 在 Swift 中按地理位置排序
- python - 在 Python 中请求图像 URL 时出现 403 - 在本地工作,但在 PythonAnywhere 上不工作
- flutter - Flutter Using ListView.Builder:我如何在我选择的所有项目上仅更改一项的背景颜色
- python - 使用 Motor AsyncIO 和 Pytest 测试 MongoDB 功能
- github - 跟踪版本控制中的变化:Github 与 Azure DevOps
- java - 在扫描仪输出后打印在同一行
- php - 如何使用 PHP 删除空值?
- heroku - 如何为数据科学目的存储heroku日志?