PDA

View Full Version : Using MsoLineJoinStyle



Chris Macro
03-13-2014, 12:02 PM
Hi I've been scratching my head on this one. I have been working on a macro that adds a custom border to every picture in a Word document. I am using Word 2013 and want to square off the borders instead of have them round. I believe I need to use msoLineJoinMiter but am not sure how to write the code. Below is what I have so far and I have commented out where I am trying to square off the edges as it appears that Microsoft defaults borders to have rounded edges. Here's a link to the on this (sorry, looks like I don't have enough post cred to use hyperlinks.....):

msdn.microsoft.com/en-us/library/office/microsoft.office.core.msolinejoinstyle.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Any help would be much appreciated!!!



Dim myPic As InlineShapeDim MyAnswer As Integer

'Loop Through All Pictures (aka Inline Shapes) in Document
For Each myPic In ActiveDocument.InlineShapes
'Select Image so user can see what image we are talking about
myPic.Select

'Ask and receive verification from user via Messagebox
MyAnswer = MsgBox("Do you wish to add border to selected image?", vbYesNo, "Add Border")

'See if User wants to add border
If MyAnswer = vbYes Then
AddBorder = Dialog

'Border Thickness
myPic.Line.Weight = 6
'Border Line Style
myPic.Line.Style = msoLineSingle
'Square Edges = MsoLineJoinStyle 'Bevel, Mixed, Round, Miter
'Border Color
myPic.Line.ForeColor.RGB = RGB(45, 44, 42)
End If

Next myPic

gmaxey
03-14-2014, 04:33 AM
Chris,

A few years ago I similarly was scratching my head of this and the line "cap" attribute. As best I can tell, there are features with enumerations in the Word 2013 graphic engine which are simply not exposed in VBA. If you do prove that wrong, please let us know.

Chris Macro
03-14-2014, 05:29 AM
Thanks for the reply Greg. I was afraid that was the case :(

snb
03-17-2014, 03:42 AM
Sub M_snb()
For Each sh In ActiveDocument.InlineShapes
sh.SoftEdge.Radius = 0
sh.Line.Weight = 4
sh.Line.Style = msoLineSingle
sh.Line.ForeColor.RGB = RGB(45, 44, 42)
Next
End Sub

gmaxey
03-17-2014, 04:19 AM
snb,

Did you test this? Here at least, it has nothing to do with the issue or question asked.

snb
03-17-2014, 05:19 AM
@gmaxey


.... a macro that adds a custom border to every picture in a Word document.
I am using Word 2013 and want to square off the borders instead of have them round

That's what my code is performing in Word 2010.

gmaxey
03-17-2014, 05:35 AM
snb,

The question and issue is related to Word 2013.

Actually your code is not doing what the OP is after. Your code is putting a border around the picture yes, but where those lines "join" at the corners is not mitered. They are slightly rounded.

Word 2013 graphics engine allows you to join borders in one of three ways: 1) Round (like yours), 2) Bevel or 3) Miter. Miter creates a sharp square corner. There is no apparent way to do this using VBA.

snb
03-17-2014, 06:30 AM
That's exactly what's also possible in Word 2010.

I'm sorry to disappoint you.
See the attachment.

snb
03-17-2014, 06:34 AM
11411

gmaxey
03-17-2014, 07:12 AM
snb,

You have not disappointed me, however I feel like I am debating with a sign board. I concede, the graphics engine with this feature was introduced with Word 2010. Still, your code does not apply a mitered join, it applies a rounded join (here at least) and there is no apparent way to set\change the join type with VBA.

Now I will be delighted to be proven incorrect, so if you can produce code that will change the join type of a picture border from round to miter then to bevel then please do so.

11412

Chris Macro
03-17-2014, 07:32 AM
Could the problem be that in 2010, Word defaults to have the Miter join and in 2013 Word defaults to have a round join? I'm guessing that is why snb's code appears to be working for him but doesn't work on our side. I find it weird that Microsoft has a page describing this (see the link I posted in my original question) however it doesn't seem possible to access it in Word. Is that webpage just for VB?

snb
03-17-2014, 07:47 AM
I must have changed the property 'join' into 'miter' manually.

gmaxey
03-17-2014, 08:09 AM
Chris,

No. In Word 2010, I can insert a picture and apply a border manually with the mitered corners and then insert another picture and run snb's code and it has rounded corners.

Chris Macro
03-17-2014, 08:14 AM
Chris,

No. In Word 2010, I can insert a picture and apply a border manually with the mitered corners and then insert another picture and run snb's code and it has rounded corners.

Gotcha....sounds like snb manually changed the setting. Thank you both for your input!