资讯动态

Word文档批量添加题注

发布时间:2026/10/23 2:20:19 来源:尧图企业网站定制
一个项目文档如果没有题注会显得格外不专业几百页的文档手动添加又会变得非常麻烦可以通过vba脚本来快速实现。SubBatchAddChapterCaption()DimimgAsInlineShapeDimrngAsRangeDimchapNumAsStringDimpicIdxAsLong 字典记录每个章节下图片序号DimdictAsObjectSetdictCreateObject(Scripting.Dictionary)Application.ScreenUpdatingFalsepicIdx0For EachimgInActiveDocument.InlineShapesIfimg.TypewdInlineShapePictureThenpicIdxpicIdx1Setrngimg.Range 关键获取图片所在章节自动编号 chapNumGetCurrentChapterNumber(rng)IfchapNumThenchapNum0.0.0 统计当前章节内第几张图 Ifdict.Exists(chapNum)Thendict(chapNum)dict(chapNum)1Elsedict(chapNum)1EndIf 拼接题注可自定义后缀文字 DimcapTextAsString 格式图 2.3.1-2 自定义文字 capText 图 chapNum - dict(chapNum) 列表查询-1capText图 chapNum-dict(chapNum) 在图片下方新建段落插入题注 rng.Collapse Direction:wdCollapseEnd rng.InsertParagraphAfter rng.Move Unit:wdParagraph rng.TextcapText 你原有格式宋体、小五、居中 Withrng.Font .Name宋体.Size9EndWithrng.ParagraphFormat.AlignmentwdAlignParagraphCenter 段前/段后小幅间距符合论文规范rng.ParagraphFormat.SpaceBefore3rng.ParagraphFormat.SpaceAfter3EndIfNextimg Application.ScreenUpdatingTrueMsgBox完成共生成 picIdx 张章节式题注,vbInformationEndSub【自定义函数】获取 章节编号 标题文字如2.3.1列表查询PrivateFunctionGetCurrentChapterNumber(ByValrngAsRange)AsStringDimparaAsParagraphSetpararng.Paragraphs(1) 向上查找最近的 带自动编号的标题DoWhileNotparaIsNothingIfpara.Range.ListFormat.ListTypewdListOutlineNumberingThen 获取编号 标题文字无空格GetCurrentChapterNumberReplace(para.Range.ListFormat.ListStringpara.Range.Text,Chr(13),)ExitFunctionEndIfSetparapara.PreviousLoopGetCurrentChapterNumber无章节EndFunction

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑