|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
交流,小弟水平很挫,这是之前写的给单个公式添加编号的宏。
方法就是选中公式嵌入式对象,执行后就自动在右侧添加好编号,且交叉引用时不会出错。
方法是先计算图片的大小和尺寸,将图片左缩进到正中间位置,插入样式分隔符,再插入公式域。。。- Sub 插入公式编号()
- Application.ScreenUpdating = False
- Dim a As Boolean
- a = (Selection.Type <> wdSelectionInlineShape)
- If a Then
- MsgBoxEx 0, "未选定公式或者公式不是嵌入型" & vbCrLf & "本功能需要先选中嵌入型公式对象", "本窗口5s内自动关闭", vbOKOnly, 0, 4500
- Else
- Dim L!, r!, pgW!, shW!, pg!, i&
- pgW = ActiveDocument.PageSetup.PageWidth
- shW = Selection.InlineShapes(1).Width
- With ActiveDocument.PageSetup
- L = .LeftMargin
- R = .RightMargin
- End With
- With Selection.ParagraphFormat
- .SpaceBeforeAuto = False
- .SpaceAfterAuto = False
- .FirstLineIndent = (pgW - L - r - shW) / 2
- .Alignment = wdAlignParagraphLeft
- End With
- With Selection
- .EndKey
- pg = .Information(wdHorizontalPositionRelativeToTextBoundary)
- .Paragraphs.TabStops.Add pg, wdAlignTabLeft '在图片右边插入一个左对齐制表符
- .Paragraphs.TabStops.Add CentimetersToPoints(15.5), wdAlignTabRight '页面最右端插入一个右对齐制表符
- .TypeText vbTab
- i = .Start '
- .TypeParagraph '这三行为消除Bug而设,否则会影响下文内容
- ActiveDocument.Range(i, i).Select '
- .InsertStyleSeparator
- .MoveLeft wdCharacter, 1, wdExtend
- .Delete
- .TypeText ("(")
- With CaptionLabels("公式")
- .NumberStyle = wdCaptionNumberStyleArabic
- .IncludeChapterNumber = True
- .ChapterStyleLevel = 1
- .Separator = wdSeparatorPeriod
- End With
- .InsertCaption Label:="公式", TitleAutoText:="", Title:="", _
- Position:=wdCaptionPositionAbove, ExcludeLabel:=1
- .TypeText (")")
- End With
- End If
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|