
WORD VBA 获取所选文字宽度
2个回答
展开全部
没找到专门的选中文本的方法可以直接计算,但可以用以下方式得到计算结果。
Sub chang()
Dim a As Integer
a = Len(Selection.Text)‘selection.text表示选中的文本,len方法计算选中字符串长度
MsgBox a
End Sub
Sub chang()
Dim a As Integer
a = Len(Selection.Text)‘selection.text表示选中的文本,len方法计算选中字符串长度
MsgBox a
End Sub
追问
不是获得字符个数,是文本宽度,如多少cm
追答
换个程序。
预先知识:选中字体的宽度= 选中文字个数×字体字号(磅数)×(1磅对应0.035cm/磅)
Sub changdu()
Dim zh, zgs As Single ‘zh表示字号,zgs表示选中文字个数
zh = Selection.Font.Size
zgs = Len(Selection.Text)
MsgBox zh * zgs * 0.035 ' 显示选中文字的宽度(单位:cm)
End Sub
展开全部
sub 问宽度()
Dim 所选宽度 as single
with selection
所选文本宽度=activedocument.range(.end,.end).information(wdhorizontalpositionrelativetopage)-activedocument.range(.start,.start).information(wdhorizontalpositionrelativetopage)
end with
end sub
Dim 所选宽度 as single
with selection
所选文本宽度=activedocument.range(.end,.end).information(wdhorizontalpositionrelativetopage)-activedocument.range(.start,.start).information(wdhorizontalpositionrelativetopage)
end with
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |