搜档网
当前位置:搜档网 › word公式居中标号右对齐的宏

word公式居中标号右对齐的宏

Sub CaptionRight()
Dim Align As Integer
On Error GoTo Bye
' If insertion point is in a table, show message and end macro.
If https://www.sodocs.net/doc/449316860.html,rmation(wdWithInTable) Then
MsgBox "You are in a table. Please move outside of the " _
& "table to run this macro.", vbInformation
GoTo Bye
End If
' Ask whether to center or left align equation.
Align = MsgBox("Would you like the Equation to be " & "centered? " _
& "(Selecting No will left-align the " & "Equation.)", vbYesNoCancel)
If Align > 2 Then
Selection.InsertParagraphAfter
Selection.Collapse Direction:=wdCollapseEnd
W = ActiveDocument.PageSetup.PageWidth
L = ActiveDocument.PageSetup.LeftMargin
R = ActiveDocument.PageSetup.RightMargin
RTMarg = W - R - L
CaptionLabels.Add Name:="("
If Align = 6 Then
tblT1 = Selection.Tables.Add(Selection.Range, 1, 3)
Else
tblT1 = Selection.Tables.Add(Selection.Range, 1, 2)
End If
tblT1.Select
With Selection
' Do this if Center-align selected.
If Align = 6 Then
.Columns(1).Cells.Width = 50.4
.Columns(3).Cells.Width = 50.4
.Columns(2).Cells.Width = RTMarg - 100.8
'Represents 1.5" in Points
Else
' Do this if Left-align selected.
.Columns(2).Cells.Width = 50.4
.Columns(1).Cells.Width = RTMarg - 50.4
'Represents .75" in Points
End If
.InsertCaption Label:="(", _
Position:=wdCaptionPositionBelow, Title:=" )"
.HomeKey unit:=wdLine, Extend:=wdExtend
.Cut
.MoveRight unit:=wdCharacter, Extend:=wdExtend
.Delete
.MoveLeft unit:=wdCharacter, Count:=2
.Paste
.Rows(1).Select
' Set the table borders to None.
For Each x In Selection.Borders
x.LineStyle = wdLineStyleNone
Next x
.Borders.Shadow = False
.Cells(9 - Align).Select
.ParagraphFormat.Alignment = wdAlignParagraphRight
.Cells(1).VerticalAlignment = wdCellAlignVerticalCenter
.Font.Bold = True
.Rows(1).Select
If Align = 6 Then
.Cells(2).Select
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InlineShapes.AddOLEObject ClassType:="Equation.3", _
FileName:="", LinkToFile:=True, DisplayAsIcon:=False
Else
.Collapse
.InlineShapes.AddOLEObject ClassType:="Equation.3", _
FileName:="", LinkToFile:=True, DisplayAsIcon:=False
End If
End With
End If
Bye:
End Sub

相关主题