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

发布时间 2023-05-07 09:31:47作者: yzhyingcool

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

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

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

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

扩展一下:

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

refer:WdUnits enumeration (Word) | Microsoft Learn

②在Excel中VBA实现该操作代码如下:

'方框选中符号
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