none
Graphic border macro RRS feed

  • Question

  • I have just started to work with large docs in word and need some macro help.

    As Word 2010 (or before) cannot record a macro that selects and formats a graphic, I need a macro code that will add a 1.25 pt width border to a graphic that is RGB 0,119,192 blue. I have esperimented with the code that was provided in a provious string that set a border, but couldn't get the color to change nor strip out some of the other commands. Any help would be appreciated.

    Thanks,

    Tom

    Tuesday, May 14, 2013 4:43 PM

Answers

  • Hi Tom,

    Below is some code that hopefully gets you started.

    Sub WorkingWithShapes()
        Dim doc As Word.Document
        Dim shp As Word.Shape
        Dim iShp As Word.InlineShape
        
        Set doc = ActiveDocument
        
        With Application.Options
            .DefaultBorderLineStyle = Word.WdLineStyle.wdLineStyleSingle
            .DefaultBorderLineWidth = Word.WdLineWidth.wdLineWidth150pt
            .DefaultBorderColor = Word.WdColor.wdColorAutomatic
        End With
        
        For Each shp In doc.Shapes
            shp.Line.Visible = True
            shp.Fill.ForeColor.RGB = RGB(0, 119, 192)
        Next shp
        
        For Each iShp In doc.InlineShapes
            iShp.Line.Visible = True
            iShp.Fill.ForeColor.RGB = RGB(0, 119, 192)
        Next iShp
    
    End Sub
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, May 14, 2013 9:25 PM
  • Hi Tom,

    No I am wrong... don't use those presets, there appears to be something wrong with them. Instead insert this code into each of the "For Each" loops that I gave you.

            shp.Line.Weight = 1.25
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, May 14, 2013 10:23 PM

All replies

  • Hi Tom,

    Below is some code that hopefully gets you started.

    Sub WorkingWithShapes()
        Dim doc As Word.Document
        Dim shp As Word.Shape
        Dim iShp As Word.InlineShape
        
        Set doc = ActiveDocument
        
        With Application.Options
            .DefaultBorderLineStyle = Word.WdLineStyle.wdLineStyleSingle
            .DefaultBorderLineWidth = Word.WdLineWidth.wdLineWidth150pt
            .DefaultBorderColor = Word.WdColor.wdColorAutomatic
        End With
        
        For Each shp In doc.Shapes
            shp.Line.Visible = True
            shp.Fill.ForeColor.RGB = RGB(0, 119, 192)
        Next shp
        
        For Each iShp In doc.InlineShapes
            iShp.Line.Visible = True
            iShp.Fill.ForeColor.RGB = RGB(0, 119, 192)
        Next iShp
    
    End Sub
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, May 14, 2013 9:25 PM
  • Thanks Rich,

    This did get borders on all the graphics, however not the width or color needed. The line width that I ended up with was .75 pt. I tried to change the width but received a compile error. (I changed the value from 150pt to 200pt in the code.)

    Tuesday, May 14, 2013 9:43 PM
  • Hi Tom,

    You have to use the preset point widths that Word allows. Try 225, 300, 450, or 600. When you type the line "Word.WdLineWidth..." it will show you the available choices.

    Regarding RGB, that was the values you specified so you'll have to look at your requirements document to see where the error is.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, May 14, 2013 10:01 PM
  • Hi Tom,

    No I am wrong... don't use those presets, there appears to be something wrong with them. Instead insert this code into each of the "For Each" loops that I gave you.

            shp.Line.Weight = 1.25
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, May 14, 2013 10:23 PM
  • Rich,

    I added your last and after changing

    "shp.Fill.ForeColor.RGB =" to

    "shp.Line.ForeColor.RGB ="

    it works great. Thanks for your help!

    Tom

    Wednesday, May 15, 2013 3:29 PM