【发布时间】:2018-12-21 04:00:24
【问题描述】:
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
【问题讨论】:
-
抱歉,我不明白您需要设置或获取属性吗?
-
我有一个形状(例如六边形),它定义了我添加到形状的形状数据。我想添加、更新特定的形状数据值。所以我希望形状数据 Prop.Object 有一个值,例如通过宏更新的“文本”。