admin管理员组

文章数量:1122847

【vba

Sub addTz()Word.Application.ScreenUpdating = FalseDim oRng As RangeDim oDoc As DocumentDim oCL As CaptionLabelDim oIS As InlineShapeSet oDoc = Word.ActiveDocumentWith oDocSet oCL = Word.CaptionLabels.Add("图")'设置新增的题注样式With oCL.ChapterStyleLevel = 1.IncludeChapterNumber = True.NumberStyle = wdCaptionNumberStyleArabicEnd Withi = 1For Each oIS In .InlineShapesSet oRng = .Range(oIS.Range.End + 1, oIS.Range.End + 1)With oRng'防止影响下段格式.InsertAfter (vbCrLf)'将oRng对象按照整个段落选中,oRng对象自动变为整个段落的Range对象oRng.Expand wdParagraph'如果有自动编号 删除oRng.ListFormat.RemoveNumbers'读取标题的文本内容sText = VBA.Replace(oRng.Text, Chr(13), "").Delete'插入题注.InsertCaption "图", sText'插入xx如yy所示的交叉引用.InsertAfter "所示" & Chr(13)'重新定义区域.SetRange .Start, .Start.InsertCrossReference "图", wdOnlyLabelAndNumber, ioRng.Expand wdParagraph.SetRange .Start, .Start.InsertBefore sText & "如"End Withi = i + 1NextEnd WithWord.Application.ScreenUpdating = True
End Sub

本文标签: VBA