Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Trying to make a macro that creates a textbox with a line in it

    Hi,

    I am trying to get a macro to work but it doesnt seem to want to play ball.

    I can get it to do what i want if i create 2 macros which i have below

    Any help would be greatly appreciated

    Sub Box()
    '
    ' Box Macro
    '
    '

    Dim Box As Shape
    Set Box = ActiveDocument.Shapes.AddTextbox( _
    Orientation:=msoTextOrientationHorizontal, _
    Left:=475, Top:=150, Width:=100, Height:=100)

    Box.Line.Visible = msoFalse

    Box.TextFrame.TextRange = "<<Insert text here>>"

    Box.TextFrame.TextRange.Borders.InsideLineStyle = Options.DefaultBorderLineStyle
    Box.TextFrame.TextRange.Borders.InsideLineWidth = Options.DefaultBorderLineWidth
    Box.TextFrame.TextRange.Borders.InsideColor = -671039489

    Set Box = Nothing

    End Sub


    Sub Line()
    '
    ' Line Macro
    '
    '
    With Selection.Borders(wdBorderLeft)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = -671039489
    End With
    End Sub

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi silentbob,

    Welcome to the Lounge.

    Your 'Inside' code doesn't actually do anything in this context, and changing the 'Inside' references to 'Outside' (or just deleting the 'Inside' strings) would apply a border to the whole box. Try:
    Code:
    Sub Box()
    Dim Box As Shape
    Set Box = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
    Left:=475, Top:=150, Width:=100, Height:=100)
    With Box
      .Line.Visible = msoFalse
      With .TextFrame.TextRange
        .Text = "<<Insert text here>>"
        With .Borders(wdBorderLeft)
          .LineStyle = Options.DefaultBorderLineStyle
          .LineWidth = Options.DefaultBorderLineWidth
          .Color = -671039489
        End With
      End With
    End With
    Set Box = Nothing
    End Sub
    PS: When posting code, please use the code tags.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks heaps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •