Macro to add borders to an image in Word 2007

D

Dee Vincent-Day

I have with the help of a friend created the following macros to add borders
to an image in Word 2007.

My problem is that if you accidentally add the dashed border and then try
adding the solid border your macro command is ignored. So once the image has
a dashed border you don't seem able to change it to a solid line.

Sub DashedBorder()
'
' DashedBorder Macro
'
'
Selection.InlineShapes(1).Line.Weight = 0.25
Selection.InlineShapes(1).Line.DashStyle = msoLineLongDash
Selection.InlineShapes(1).Line.Visible = msoCTrue
Selection.InlineShapes(1).Line.ForeColor.RGB = RGB(79, 129, 189)

End Sub

Sub SolidBorder()
'
' SolidBorder Macro
'
'
Selection.InlineShapes(1).PictureFormat
Line.Weight = 0.25
Selection.InlineShapes(1).Line.Style = msoLineSolid
Selection.InlineShapes(1).Line.Visible = msoCTrue
Selection.InlineShapes(1).Line.ForeColor.RGB = RGB(79, 129, 189)

End Sub

I know I can reset the image but that will also remove any other custom
formatting such as resizing. I also tried changing the LineVisible
property to msoFalse but that seems to simply turn the line off. If you then
apply the solid line you still get a dashed line.

I would like this as a button macro because a couple of times I have
forgotten to change the line width or style. It would be so much easier to
have this combined into one button click.

If someone can suggest a way of physically removing the line altogether
without resetting all of the image formatting I would happily add that to
another button.
 
J

Jay Freedman

You and your friend have confused the .Style property and the
..DashStyle property. The DashedBorder macro is setting the .DashStyle
property to the long dash. Because the SolidBorder macro is setting
the .Style property instead of the .DashStyle property, it isn't
changing the dash style.

It just happens that the constant msoLineSolid used in the SolidBorder
macro has the value 1, which is the same as the value of the
msoLineSingle constant. Since the dashed border is already single (as
opposed to double or one of the thick-thin combinations), it appears
that nothing happens.

To fix this, change the line in the SolidBorder macro to

Selection.InlineShapes(1).Line.DashStyle = msoLineSolid

You also have a mistyped statement in the line before that -- as
shown, that line should cause a compile error "Invalid use of
property". Instead, the line should be the same as the corresponding
line in the DashedBorder macro,

Selection.InlineShapes(1).Line.Weight = 0.25

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
D

Dee Vincent-Day

Hello Jay,

many thanks for responmding. I did get there myself after a little trial
and error but your explanation has made clear the mistake we made.

Thank you again.

Regards

Dee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top