首页 > 解决方案 > 如何设置形状数据的值

问题描述

Visio VBA 宏:我希望在程序将形状拖放到页面后设置形状形状数据的值。我用 5 个定义的数据形状字符串创建了一个十六进制形状。

我曾尝试寻找答案,但没有找到有关如何执行此操作的明确说明

   Dim strConnection As String
Dim strCommand As String
Dim strOfficePath As String
Dim cellString As String
Dim vsoDataRecordset As Visio.DataRecordset
Dim vsoCell As Visio.Cell

strOfficePath = Visio.Application.Path

strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
                   & "User ID=Admin;" _
                   & "Data Source=svs2.XLSX;" _
                   & "Mode=Read;" _
                   & "Extended Properties=""HDR=YES;IMEX=1;MaxScanRows=0;Excel 12.0;"";" _
                   & "Jet OLEDB:Engine Type=34;"

strCommand = "SELECT * FROM [BaseTemplate$]"

Set vsoDataRecordset = ActiveDocument.DataRecordsets.Add(strConnection, strCommand, 0, "Data")

MsgBox "Connected Up:" & vsoDataRecordset.DataColumns(1)

'Get the row IDs of all the rows in the data recordset
lngRowIDs = vsoDataRecordset.GetDataRowIDs("")


'Iterate through all the records in the data recordset.
For lngRow = LBound(lngRowIDs) + 1 To UBound(lngRowIDs) + 1

    varRowData = vsoDataRecordset.GetRowData(lngRow)
    'varRowData = vsoDataReco


    'Drop Shape onto page
    Set shpObject = pagThisPage.Drop(Application.Documents("microservices V2.VSS").Masters("Microservice"), 0#, 0#)

    'Update Shapes Text
    shpObject.Text = varRowData(0)

    'Get cell that i want to update
    Set vsoCell = shpObject.Cells("Prop.Object")

    'Copy data i want to apply to shape to string
    cellString = varRowData(0)

    vsoCell.Formula = cellString


    'get shape data value to print out
    dt = shpObject.Cells("Prop.Object").ResultStr("")

    MsgBox "---" & dt & ":" & vsoCell.Formula

Next lngRow

标签: vbavisio

解决方案


形状数据保存在 ShapeSheet 中。您可以访问 ShapeSheet 单元格以输入信息,也可以访问 ShapeSheet 单元格以获取信息。

Set vsoCell = shpObject.Cells("Prop.Object")- 这假设您在 ShapeSheet 中有名为“对象”的适当属性(行)。您还有“用户”。可以使用的细胞。

现在您可以简单地使用您的对象vsoCell来填充信息(例如vsoCell.Formula = "Scratch.X1") - 您可能需要双引号来放入文字字符串,而不是公式。

采用通用形状,添加一些形状数据,然后打开 shapesheet 以查看其存储方式。这将为您提供一些关于调用什么名称以及如何操作这些数据的想法。ShapeSheet 是 Visio 模型中一个非常强大的部分,一旦您学会了如何管理它,您就可以做一些非常好的事情。


推荐阅读