How to add a custom page border to a Word Document
-
Tuesday, May 10, 2011 2:16 PM
Hi to all,
I'm developing a Word AddIn based on Word 2007 with Visual Studio 2010 and Visual Basic.
It's possible to add a custom page border to a Word Document ?
Thanks for any help.
All Replies
-
Tuesday, May 10, 2011 2:38 PM
Hi Fabrizio,
A fast way to get the base code for any standard Word function is to record the process from Word VBA and then adapt it to your add-in’s language and syntax requirements. Below is a recording of the VBA to set a custom page boarder on a one section Word document.
Sub Macro13()
'
' Macro13 Macro
'
'
With Selection.Sections(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth600pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth600pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth600pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth600pt
.Color = wdColorAutomatic
End With
With .Borders
.DistanceFrom = wdBorderDistanceFromPageEdge
.AlwaysInFront = True
.SurroundHeader = True
.SurroundFooter = True
.JoinBorders = False
.DistanceFromTop = 24
.DistanceFromLeft = 24
.DistanceFromBottom = 24
.DistanceFromRight = 24
.Shadow = False
.EnableFirstPageInSection = True
.EnableOtherPagesInSection = True
.ApplyPageBordersToAllSections
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth600pt
.DefaultBorderColor = wdColorAutomatic
End With
End Sub
Hope this helps
Regards, Rich -
Tuesday, May 10, 2011 2:48 PM
Hi Rich Michaels,
thanks for your reply.
Word has a long list of builtin page borders such as "Cake,Apple,Ice Cream,..".
It's possible to add my custom page border to this list and use it on my Word AddIn ?
-
Tuesday, May 10, 2011 3:16 PM
You can't add anything to a list in a built-in dialog. At least, this isn't allowed in the Word object model. There sre two ways out. A) you provide a control (say, a button) which allows the user to access your functionality. Or, you can create a form providing functionality similar to that provided by the built-in dialog (including an entry specifying the border style of your own) and show that form instead of the built-in one when the user shows up the built-in dialog.
In the second scenario, you'll need to handle two cases: the user clicks the item in the main menu (or context menu) or the user presses some key combination responsible for showing that dialog.
Regards from Belarus (GMT + 2),
Andrei Smolin
Add-in Express Team Leader- Proposed As Answer by Tom_Xu_WXModerator Tuesday, May 17, 2011 7:20 AM
- Marked As Answer by Tom_Xu_WXModerator Wednesday, May 18, 2011 5:27 AM

