请教怎么把数字变成上标的形式。word vba

wordVBA

1个回答

写回答

Thjbgy

2025-12-02 05:00

+ 关注

word
word

我刚写了个word宏,专门用来把文档里的数字设成上标,效果挺不错的,分享给大家看看:VBASub shangbiao() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = ^ '查找所有数字 .Replacement.Text = ^^&' With .Replacement.Font' .Superscript = True' .Subscript = False' End With Selection.Font.Superscript = True .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeword = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllwordForms = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub

这个宏的思路就是用通配符^来匹配所有数字,然后替换成同样的内容,并把这部分字体设置成上标。目前注释掉的那一段是原本打算用来设置字体样式的,不过我发现直接设置Selection.Font.Superscript = True更简单粗暴,效果也不错。大家如果在用word处理文献引用、脚注啥的,这个宏应该挺实用的。如果你有啥优化建议,或者发现啥bug,欢迎留言交流哈~

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号