title: Resizing a Visio shape through Visual Basic
body: <p>So I've been working on trying to resize a Visio box in Visual Basic for a project in work, using some code that was given to me as I am very new to Visual Basic. 
  I have tried many methods without any result, and I am now working on using the Shape.Resize() method which works but then throws an error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>On line 6, I get the error "Run-time error '13': Type mismatch", but the code still executes before throwing this error (ie; the width of the shape changes but the code stops at this line.) Here is the code for the CreateVisioObject:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Here is the reference for the Shape.Resize() - <a href="https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-resize-method-visio" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-resize-method-visio</a></p>
  
  <p>Also, the code is using an Excel sheet to generate the Visio document.</p>
  
  <p>Thank you for your help!</p>