News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

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 ?

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 166 (show)
Files included: 35 - 1357KB. (show)
Memory used: 1055KB.
Tokens: post-login.
Cache hits: 13: 0.00169s for 26,770 bytes (show)
Cache misses: 2: (show)
Queries used: 17.

[Show Queries]