从宏设置Visio文档形状表中用户定义的单元格值



我在Visio主文档形状表的"用户定义的单元格"部分添加了一行,名为"用户版本"。我可以通过添加一个字段集来使用绘图中的值,该字段集使用自定义公式=TheDoc!用户版本

我想要一个宏来设置这个单元格值,但我找不到在VBA中引用用户定义单元格的方法。TheDoc!用户。修订不起作用。

所以这有点晚了,但我想有些人可能仍然可以使用它。

文档的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

最新更新