T
Top Spin
I want to thank everyone who helped me get this little macro working.
I am posting the completed macro in case it might be useful to anyone.
I would be interested in any comments on the coding or logic.
If it is not appropriate to post code, please advise and I won't do it
again.
Thanks
'=====================================================================
' Macro: ParaSpaceBefDec6pts, Recorded on 07/21/04
'
' Assigned to Ctrl+Shift+{ 'Parallels Ctrl+[
'
' Decrease the paragraph Space Before setting by 6 pts (-6).
' See also ParaSpaceBefInc6pts
'=====================================================================
Sub ParaSpaceBefDec6pts()
Const sMacName As String = "ParaSpaceBefDec6pts"
Call ParaSpaceBef6pts("-6", sMacName)
End Sub
'=====================================================================
' Macro: ParaSpaceBefInc6pts, Recorded on 07/21/04
'
' Assigned to Ctrl+Shift+} 'Parallels Ctrl+]
'
' Increase the paragraph Space Before setting by 6 pts (+6).
' See also ParaSpaceBefDec6pts
'=====================================================================
Sub ParaSpaceBefInc6pts()
Const sMacName As String = "ParaSpaceBefInc6pts"
Call ParaSpaceBef6pts("+6", sMacName)
End Sub
'=====================================================================
' Macro: ParaSpaceBef6pts, Recorded on 07/21/04
'
' Called by ParaSpaceBefInc6pts & ParaSpaceBefDec6pts
'
' Syntax: Call ParaSpaceBef6pts(parm, macname)
'
' parm "+" = Increase the paragraph Space Before setting by 6 pts.
' "-" = Decrease the paragraph Space Before setting by 6 pts.
' macname = Name of caller
'
' If it's set to 'Auto' or if the selection is not all the same,
' ask for instructions.
'=====================================================================
Sub ParaSpaceBef6pts(sParm As String, sMacName As String)
Dim nSpBefOld As Single, nSpBefNew As Single 'Settings, old and new
Dim lAmt As Long 'Inc/dec amount (+6/-6)
Dim lBase As Long 'Base amount (6/0)
Dim lReply As Long, sMsg As String
If sParm = "+6" Then 'Check the input parms: "+6" or "-6"
lAmt = 6: lBase = 6
ElseIf sParm = "-6" Then
lAmt = -6: lBase = 0
Else
sMsg = "Logic Error:" & vbCrLf _
& "Invalid parameter (" & sParm & ") from " & sMacName & "." &
vbCrLf _
& "Operation aborted."
Call MsgBox(sMsg, , "ParaSpaceBef6pts")
Exit Sub
End If
'Display the settings (debug). Comment out when not needed.
'sMsg = "Selection.ParagraphFormat.SpaceBefore = " &
Selection.ParagraphFormat.SpaceBefore & vbCrLf _
' & "Selection.ParagraphFormat.SpaceBeforeAuto = " &
Selection.ParagraphFormat.SpaceBeforeAuto
'Call MsgBox(sMsg, , sMacName)
'Exit Sub
nSpBefOld = Selection.ParagraphFormat.SpaceBefore
'If there are different settings (9999999), ask for instructions
'This must be done before the 'Auto' check.
If nSpBefOld > 9999 Then
sMsg = "The selection contains multiple paragraph Space Before
settings. " _
& "Set them all to " & lBase & "?"
lReply = MsgBox(sMsg, vbYesNoCancel + vbDefaultButton2, sMacName)
If lReply = vbYes Then 'If they say yes, set them all to 0/6
nSpBefNew = lBase
GoTo SetEm
Else 'Otherwise, do nothing
Exit Sub
End If
End If
'If the setting is "Auto" (-1), ask for instructions
If Selection.ParagraphFormat.SpaceBeforeAuto = -1 Then
sMsg = "The current paragraph Space Before setting is 'Auto'. " _
& "Set it to " & lBase & "?"
lReply = MsgBox(sMsg, vbYesNoCancel + vbDefaultButton2, sMacName)
If lReply = vbYes Then 'If they say yes, set them all to 0 (&
reset 'Auto')
nSpBefNew = lBase
GoTo SetEm
Else 'Otherwise, do nothing
Exit Sub
End If
End If
'If the setting < 6, ask for instructions (Decrement only)
'(Probably OK to just set it to 0)
If sParm = "-6" Then
If nSpBefOld < 6 Then
sMsg = "The current paragraph Space Before setting (" & nSpBefOld &
") is < 6. " _
& "Set it to 0?"
lReply = MsgBox(sMsg, vbYesNoCancel + vbDefaultButton2, sMacName)
If lReply = vbYes Then 'If they say yes, set them all to 0
nSpBefNew = 0
GoTo SetEm
Else 'Otherwise, do nothing
Exit Sub
End If
End If
End If
'All special conditions eliminated. Do the decrement.
nSpBefNew = nSpBefOld + lAmt
'Update the settings and exit
SetEm:
Selection.ParagraphFormat.SpaceBeforeAuto = 0 'Reset 'Auto',
just in case
Selection.ParagraphFormat.SpaceBefore = nSpBefNew 'Decrement by 6
End Sub
I am posting the completed macro in case it might be useful to anyone.
I would be interested in any comments on the coding or logic.
If it is not appropriate to post code, please advise and I won't do it
again.
Thanks
'=====================================================================
' Macro: ParaSpaceBefDec6pts, Recorded on 07/21/04
'
' Assigned to Ctrl+Shift+{ 'Parallels Ctrl+[
'
' Decrease the paragraph Space Before setting by 6 pts (-6).
' See also ParaSpaceBefInc6pts
'=====================================================================
Sub ParaSpaceBefDec6pts()
Const sMacName As String = "ParaSpaceBefDec6pts"
Call ParaSpaceBef6pts("-6", sMacName)
End Sub
'=====================================================================
' Macro: ParaSpaceBefInc6pts, Recorded on 07/21/04
'
' Assigned to Ctrl+Shift+} 'Parallels Ctrl+]
'
' Increase the paragraph Space Before setting by 6 pts (+6).
' See also ParaSpaceBefDec6pts
'=====================================================================
Sub ParaSpaceBefInc6pts()
Const sMacName As String = "ParaSpaceBefInc6pts"
Call ParaSpaceBef6pts("+6", sMacName)
End Sub
'=====================================================================
' Macro: ParaSpaceBef6pts, Recorded on 07/21/04
'
' Called by ParaSpaceBefInc6pts & ParaSpaceBefDec6pts
'
' Syntax: Call ParaSpaceBef6pts(parm, macname)
'
' parm "+" = Increase the paragraph Space Before setting by 6 pts.
' "-" = Decrease the paragraph Space Before setting by 6 pts.
' macname = Name of caller
'
' If it's set to 'Auto' or if the selection is not all the same,
' ask for instructions.
'=====================================================================
Sub ParaSpaceBef6pts(sParm As String, sMacName As String)
Dim nSpBefOld As Single, nSpBefNew As Single 'Settings, old and new
Dim lAmt As Long 'Inc/dec amount (+6/-6)
Dim lBase As Long 'Base amount (6/0)
Dim lReply As Long, sMsg As String
If sParm = "+6" Then 'Check the input parms: "+6" or "-6"
lAmt = 6: lBase = 6
ElseIf sParm = "-6" Then
lAmt = -6: lBase = 0
Else
sMsg = "Logic Error:" & vbCrLf _
& "Invalid parameter (" & sParm & ") from " & sMacName & "." &
vbCrLf _
& "Operation aborted."
Call MsgBox(sMsg, , "ParaSpaceBef6pts")
Exit Sub
End If
'Display the settings (debug). Comment out when not needed.
'sMsg = "Selection.ParagraphFormat.SpaceBefore = " &
Selection.ParagraphFormat.SpaceBefore & vbCrLf _
' & "Selection.ParagraphFormat.SpaceBeforeAuto = " &
Selection.ParagraphFormat.SpaceBeforeAuto
'Call MsgBox(sMsg, , sMacName)
'Exit Sub
nSpBefOld = Selection.ParagraphFormat.SpaceBefore
'If there are different settings (9999999), ask for instructions
'This must be done before the 'Auto' check.
If nSpBefOld > 9999 Then
sMsg = "The selection contains multiple paragraph Space Before
settings. " _
& "Set them all to " & lBase & "?"
lReply = MsgBox(sMsg, vbYesNoCancel + vbDefaultButton2, sMacName)
If lReply = vbYes Then 'If they say yes, set them all to 0/6
nSpBefNew = lBase
GoTo SetEm
Else 'Otherwise, do nothing
Exit Sub
End If
End If
'If the setting is "Auto" (-1), ask for instructions
If Selection.ParagraphFormat.SpaceBeforeAuto = -1 Then
sMsg = "The current paragraph Space Before setting is 'Auto'. " _
& "Set it to " & lBase & "?"
lReply = MsgBox(sMsg, vbYesNoCancel + vbDefaultButton2, sMacName)
If lReply = vbYes Then 'If they say yes, set them all to 0 (&
reset 'Auto')
nSpBefNew = lBase
GoTo SetEm
Else 'Otherwise, do nothing
Exit Sub
End If
End If
'If the setting < 6, ask for instructions (Decrement only)
'(Probably OK to just set it to 0)
If sParm = "-6" Then
If nSpBefOld < 6 Then
sMsg = "The current paragraph Space Before setting (" & nSpBefOld &
") is < 6. " _
& "Set it to 0?"
lReply = MsgBox(sMsg, vbYesNoCancel + vbDefaultButton2, sMacName)
If lReply = vbYes Then 'If they say yes, set them all to 0
nSpBefNew = 0
GoTo SetEm
Else 'Otherwise, do nothing
Exit Sub
End If
End If
End If
'All special conditions eliminated. Do the decrement.
nSpBefNew = nSpBefOld + lAmt
'Update the settings and exit
SetEm:
Selection.ParagraphFormat.SpaceBeforeAuto = 0 'Reset 'Auto',
just in case
Selection.ParagraphFormat.SpaceBefore = nSpBefNew 'Decrement by 6
End Sub