通过 Visual Basic 调整 Visio 形状的大小
Resizing a Visio shape through Visual Basic
因此,我一直在努力尝试在 Visual Basic 中为工作中的项目调整 Visio 框的大小,使用了一些给我的代码,因为我对 Visual Basic 还很陌生。
我尝试了很多方法但没有任何结果,我现在正在使用 Shape.Resize() 方法,该方法有效但随后抛出错误:
If ActiveCell.Offset(0, 2).Value = "D" Then
Dim sizer As Double
sizer# = 2
iData = iData + 1
Set shp = CreateVisioObject(AppVisio, "Box", 2.5, 7.25, ActiveCell.Offset(0, 1).Value, """AccentColor4""")
Set shp = shp.Resize(0, sizer, 65)
Set shp = shp.Resize(2, sizer, 65)
End If
在第 6 行,我收到错误 "Run-time error '13': Type mismatch",但代码在抛出此错误之前仍然执行(即;形状的宽度发生变化但代码在这一行停止。)这是代码对于 CreateVisioObject:
Function CreateVisioObject(ByRef oVisio As Object, strType As String, posX As Double, posY As Double, strText As String, strColor As String) As Object
Set shp = oVisio.ActiveWindow.Page.Drop(oVisio.Documents.Item("BLOCK_U.VSS").Masters.ItemU(strType), posX, posY)
shp.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = "20 pt"
Set oCharacters = shp.Characters
oCharacters.Begin = 0
oCharacters.End = Len(oCharacters)
sChar = strText
oCharacters.Text = sChar
shp.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(THEMEVAL(" + strColor + "))"
shp.CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEMEVAL(""FillColor""),THEMEVAL(""FillColor2""))))"
shp.CellsSRC(visSectionObject, visRowGradientProperties, visFillGradientEnabled).FormulaU = "FALSE"
Set CreateVisioObject = shp
End Function
这是 Shape.Resize() - https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-resize-method-visio
的参考
此外,代码使用 Excel sheet 生成 Visio 文档。
感谢您的帮助!
我以前不知道Shape.Resize方法。当我想调整某些形状的大小时,我只需更改它 Width 和 Height
shp.Cells("width") = 2
shp.Cells("height") = 2
因此,我一直在努力尝试在 Visual Basic 中为工作中的项目调整 Visio 框的大小,使用了一些给我的代码,因为我对 Visual Basic 还很陌生。 我尝试了很多方法但没有任何结果,我现在正在使用 Shape.Resize() 方法,该方法有效但随后抛出错误:
If ActiveCell.Offset(0, 2).Value = "D" Then
Dim sizer As Double
sizer# = 2
iData = iData + 1
Set shp = CreateVisioObject(AppVisio, "Box", 2.5, 7.25, ActiveCell.Offset(0, 1).Value, """AccentColor4""")
Set shp = shp.Resize(0, sizer, 65)
Set shp = shp.Resize(2, sizer, 65)
End If
在第 6 行,我收到错误 "Run-time error '13': Type mismatch",但代码在抛出此错误之前仍然执行(即;形状的宽度发生变化但代码在这一行停止。)这是代码对于 CreateVisioObject:
Function CreateVisioObject(ByRef oVisio As Object, strType As String, posX As Double, posY As Double, strText As String, strColor As String) As Object
Set shp = oVisio.ActiveWindow.Page.Drop(oVisio.Documents.Item("BLOCK_U.VSS").Masters.ItemU(strType), posX, posY)
shp.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = "20 pt"
Set oCharacters = shp.Characters
oCharacters.Begin = 0
oCharacters.End = Len(oCharacters)
sChar = strText
oCharacters.Text = sChar
shp.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(THEMEVAL(" + strColor + "))"
shp.CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEMEVAL(""FillColor""),THEMEVAL(""FillColor2""))))"
shp.CellsSRC(visSectionObject, visRowGradientProperties, visFillGradientEnabled).FormulaU = "FALSE"
Set CreateVisioObject = shp
End Function
这是 Shape.Resize() - https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-resize-method-visio
的参考此外,代码使用 Excel sheet 生成 Visio 文档。
感谢您的帮助!
我以前不知道Shape.Resize方法。当我想调整某些形状的大小时,我只需更改它 Width 和 Height
shp.Cells("width") = 2
shp.Cells("height") = 2