通过Visual Basic调整Visio形状的大小

时间:2017-07-24 10:42:14

标签: vba resize visio

所以我一直在努力尝试在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行,我收到错误"运行时错误' 13':类型不匹配",但代码仍然在执行此错误之前执行(即;的宽度形状更改但代码在此行停止。)以下是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工作表生成Visio文档。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

之前我还不知道 Shape.Resize Method 。当我想要调整某些形状时,我只需更改宽度高度

   shp.Cells("width") = 2
   shp.Cells("height") = 2