【VBA】如何在Word表格里插入特殊符号

Word里有插入特殊符号的功能,如下图。

通过编程语言实现在Word表格插入特殊符号操作,可以参考下面VBA代码。

1
2
3
4
ActiveDocument.Tables(1).Range.Cells(2).Select
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Selection.InsertSymbol Font:="Wingdings", _
CharacterNumber:=-4014, Unicode:=True

refer:Insert symbol into cell in table (narkive.com)

扩展一下:

①Unit:=wdCharacter中的unit参数是一个枚举值,在Word以外的程序中使用时可以使用枚举值数值。

refer:WdUnits enumeration (Word) | Microsoft Learn

②在Excel VBA中后期绑定实现该操作需要注意枚举值处理,代码如下:

1
2
3
4
5
6
'方框选中符号
Sub InsertSelectedSymbolIntoTable(tableIdx As Integer, rowIdx As Integer, colIdx As Integer)
    thisDoc.Tables(tableIdx).Cell(rowIdx, colIdx).Range.Select
    wordApp.Selection.MoveEnd Unit:=1, Count:=-1 'Unit:=wdCharacter
    wordApp.Selection.InsertSymbol CharacterNumber:=-4014, Font:="Wingdings 2", Unicode:=True
End Sub

  

posted @   yzhyingcool  阅读(359)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2020-05-07 System.DllNotFoundException:“无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块 的解决方法
点击右上角即可分享
微信分享提示