![]() |
|
#1
|
||||
|
||||
|
Could some kind soul provide a simple macro to cycle among several page border settings? I'd like to assign it to a keyboard shortcut (Alt+B) and have it cycle through these settings each time I invoke it:
Using the macro recorder, I was able to create one macro to set it to #1 and one to turn it off (#4). I also have a macro that seems to detect these two, but they seem too complicated. Before I try to add steps 2 & 3, could someone critique what I have or provide better code? Thanks Code:
'===========================================================================
' Toggle Page Border (Alt-B)
' Toggle the Page Border (on/off)
' For custom cards and envelopes template, to see where the real text borders are.
'===========================================================================
Sub MyPageBorderToggle()
' Is this the right code or even necessary?
' I'm setting a page border, not a paragraph border.
With Selection.Sections(1)
If .Borders(wdBorderLeft).LineStyle Or _
.Borders(wdBorderRight).LineStyle Or _
.Borders(wdBorderTop).LineStyle Or _
.Borders(wdBorderBottom).LineStyle Then 'If any border is on,
Call MyPageBorderToggleOff 'Turn them all off.
' MsgBox "Page borders off"
Else 'If they are all off,
Call MyPageBorderToggleOn 'Turn them all on.
' MsgBox "Page borders on"
End If
End With
End Sub
Code:
Sub MyPageBorderToggleOff()
With Selection.Sections(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With
End Sub
Code:
Sub MyPageBorderToggleOn()
With Selection.Sections(1)
'' This seems redundant
With Options
' .DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth100pt
.DefaultBorderColor = wdColorAutomatic
End With
' ' Turn on each edge individually.
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
' .LineWidth = wdLineWidth025pt
' .Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
' .LineWidth = wdLineWidth025pt
' .Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
' .LineWidth = wdLineWidth025pt
' .Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
' .LineWidth = wdLineWidth025pt
' .Color = wdColorAutomatic
End With
' Relate it to the text, not the page. This must be done last.
With .Borders
.DistanceFrom = wdBorderDistanceFromText
' .AlwaysInFront = True
' .SurroundHeader = True
' .SurroundFooter = True
' .JoinBorders = False
.DistanceFromTop = 0
.DistanceFromLeft = 0
.DistanceFromBottom = 0
.DistanceFromRight = 0
' .Shadow = False
' .EnableFirstPageInSection = True
' .EnableOtherPagesInSection = True
' .ApplyPageBordersToAllSections
End With
End With
End Sub
|
|
#2
|
||||
|
||||
|
Hi Jennifer,
You can't have option 3. That aside, try: Code:
Sub Borders()
Application.ScreenUpdating = False
Dim i As Long
With Selection.Sections(1)
If .Borders(wdBorderLeft).LineStyle = wdLineStyleNone Then
For i = 1 To 4
With .Borders(i)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = wdColorAutomatic
End With
Next
With .Borders
.DistanceFrom = wdBorderDistanceFromText
.DistanceFromTop = 1
.DistanceFromLeft = 1
.DistanceFromBottom = 1
.DistanceFromRight = 1
End With
ElseIf .Borders.DistanceFrom = wdBorderDistanceFromText Then
With .Borders
.DistanceFrom = wdBorderDistanceFromPageEdge
.DistanceFromTop = 24
.DistanceFromLeft = 24
.DistanceFromBottom = 24
.DistanceFromRight = 24
End With
Else
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End If
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Page-crossing borders in a table with hidden between-cell borders
|
tenpaiman | Word | 2 | 08-08-2012 07:20 PM |
merging documents in macro page no
|
Rose_Garden | Word | 1 | 03-31-2012 04:50 AM |
| Macro to insert new page... | samanthaj | Word | 17 | 01-31-2012 01:53 PM |
| Page borders vs Orientation | Ineedcoffee | Word | 5 | 12-06-2011 12:52 PM |
Page number Macro
|
kimsi | Word | 3 | 11-15-2011 11:54 PM |