Author Topic: How to space just two shape boundaries and not all on a page  (Read 9921 times)

0 Members and 1 Guest are viewing this topic.

Jacob2021

  • Jr. Member
  • **
  • Posts: 11
I want to spaces all my shapes manually (because the auto feature sucks to be honest). In Excel I ran some VBA for this where you would select the shape you wanted to stay static, then the next click or clicks would select the shapes to move. Then I would enter a value to space them, either vertically or horizontally and it would space the shapes from the edges, not the centre. I want to do the same in Visio. Below is an example of the vertical space code. Does anyone know how I replicate this in Visio?

Code
Sub AutoSpace_Shapes_Vertical()
Sub AutoSpace_Shapes_Vertical()
'Automatically space and align shapes

Dim shp As Shape
Dim lCnt As Long
Dim dTop As Double
Dim dLeft As Double
Dim dHeight As Double
Const dSPACE As Double = 8

  'Check if shapes are selected
  If TypeName(Selection) = "Range" Then
    MsgBox "Please select shapes before running the macro."
    Exit Sub
  End If
 
  'Set variables
  lCnt = 1
 
  'Loop through selected shapes (charts, slicers, timelines, etc.)
  For Each shp In Selection.ShapeRange
    With shp
      'If not first shape then move it below previous shape and align left.
      If lCnt > 1 Then
        .Top = dTop + dHeight + dSPACE
        .Left = dLeft
      End If
     
      'Store properties of shape for use in moving next shape in the collection.
      dTop = .Top
      dLeft = .Left
      dHeight = .Height
    End With
   
    'Add to shape counter
    lCnt = lCnt + 1
   
  Next shp

End Sub

Surrogate

  • Hero Member
  • *****
  • Posts: 1607
    • ShapeSheet™ Knowledge Base
Re: How to space just two shape boundaries and not all on a page
« Reply #1 on: May 13, 2021, 11:34:40 PM »
Code
  'Check if shapes are selected
  If TypeName(Selection) = "Range" Then
    MsgBox "Please select shapes before running the macro."
    Exit Sub
  End If
 
  'Set variables
  lCnt = 1
 
  'Loop through selected shapes (charts, slicers, timelines, etc.)
  For Each shp In Selection.ShapeRange
    With shp
      'If not first shape then move it below previous shape and align left.
      If lCnt > 1 Then
        .Top = dTop + dHeight + dSPACE
        .Left = dLeft
      End If
  End Sub
Visio have another object model !

Jacob, please describe what do you want to do ?
« Last Edit: May 13, 2021, 11:37:35 PM by Surrogate »