How to space just two shape boundaries and not all on a page

Started by Jacob2021, May 14, 2021, 04:09:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jacob2021

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?

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

Quote from: Jacob2021 on May 14, 2021, 04:09:12 AM
  '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 ?