Macro for margins

Former Member
Former Member

Hey y'all, 

Would there would be a way for me to make a macro that creates 1 cm margins? I'm aware of the "/tools/options/presets/one centimeter margin" thing, but I'd like the margins to be created with one click, and not having to change the Units to centimeters every time (I usually prefer working with pixels).

Help anyone? 

oh and it's my first time here hehe.

 

 

 

  • Found this here. And with a little modification (see below)

    Also see notes where to change the Units and distance

    Sub addguides()

    Dim D As Document

    Dim p As PageSize

    Dim x As Long, y As Long

    Dim l As String

    Dim n As Double

    ActiveDocument.Unit = cdrInch 'change to units desired

    n = 1 'equals 1/2"

    '------------------------ Undo Group Start ------------------------

    ActiveDocument.BeginCommandGroup "Undo action description"

    Optimization = True

    EventsEnabled = False

    ActiveDocument.SaveSettings

    ActiveDocument.PreserveSelection = False

    l = ActiveLayer.Name

    x = ActivePage.SizeWidth - n

    y = ActivePage.SizeHeight - n

    ActivePage.Layers("Guides").CreateGuideAngle x, y, 0 ' Horizontal

    ActivePage.Layers("Guides").CreateGuideAngle x, y, 90 ' Vertical

    x = ActivePage.SizeWidth - ActivePage.SizeWidth + n

    y = ActivePage.SizeHeight - ActivePage.SizeHeight + n

    ActivePage.Layers("Guides").CreateGuideAngle x, y, 0 ' Horizontal

    ActivePage.Layers("Guides").CreateGuideAngle x, y, 90 ' Vertical

    ActiveDocument.RestoreSettings

    EventsEnabled = True

    Optimization = False

    Application.Refresh

    ActiveWindow.Refresh

    ActiveDocument.EndCommandGroup

    '------------------------ Undo Group End ------------------------

    ActiveDocument.ClearSelection

    ActivePage.Layers(l).Activate

    End Sub

    • hmmm gonna need some tweaking, doesn't seem to be getting it right every time.
      • Hi.
        Tried it once and it seemed to work fine.
        • Former Member
          Former Member over 9 years ago in reply to Myron
          At first it didn't work, the right margin was off.. but then it worked and seems to work fine every time now! Thanks a TON! :D
          • change the page size then run the macro. Right margin isn't right. Also can't adjust below 1 inch.
            • You can try this (made on X5)

              Sub Guides2()
              Dim p As Page, x#, y#, h#, w#, adu As String, adl As Layer
              ActiveDocument.BeginCommandGroup ("Guides")
              adu = ActiveDocument.Unit
              Set adl = ActiveDocument.ActivePage.ActiveLayer
              ActiveDocument.Unit = cdrMillimeter
              ActivePage.GetBoundingBox x, y, w, h
              ActivePage.GuidesLayer.Shapes.All.Delete
              Set s1 = ActivePage.GuidesLayer.CreateGuideAngle(x + 10, 148.5, 90#)
              s1.MoveToLayer ActivePage.GuidesLayer
              s1.Outline.Color.RGBAssign 0, 100, 0
              Set s2 = s1.Duplicate(w - 20, 0)
              Set s3 = ActivePage.GuidesLayer.CreateGuideAngle(0, y + 10, 0#)
              s3.MoveToLayer ActivePage.GuidesLayer
              s3.Outline.Color.RGBAssign 0, 100, 0
              Set s4 = s3.Duplicate(0, h - 20)
              ActiveDocument.ClearSelection
              ActiveDocument.Unit = acu
              ActiveDocument.EndCommandGroup
              End Sub

            • need to create guidlines outside of the page exactly o.5mm but when i am trying to change the n value to -0.5 then it shows me guide on 0.7mm please help.