文本框的下划线属性不能像其他样式一样工作 [英] Underline property of textbox not working like the others

查看:40
本文介绍了文本框的下划线属性不能像其他样式一样工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用VBA在工作表文本框中的某些文本下划线,从特定字符到另一个.它应该非常简单,并且Bold和Italic我可以做到.

I simply want to underline some text in a worksheet textbox using VBA, from a specific character to another. It should be extremely simple, and I can do it without problem with Bold and Italic.

我有以下子

Sub ew()
    Dim txt1 As Shape
    Set txt1 = Sheet1.Shapes("txt_1")
    txt1.TextFrame.Characters.Text = "Bold and Underline this"

    txt1.TextFrame.Characters.Font.Bold = True
    txt1.TextFrame.Characters.Font.Italic = True
    txt1.TextFrame.Characters.Font.Underline = True
End Sub

代码在最后一行失败,这非常奇怪,因为它适用于前两行.错误(1004)表示类似无法定义Font属性的Underline函数".

The code fails on the last line, which is extremely strange because it worked for the 2 previous lines. the error (1004) says something like "Impossible to define the Underline function of the Font property".

要重现此问题,请将我的工作带到一个新的Excel文档中,并创建一个名为"txt_1"的文本框,这就是运行它所需要的.

To recreate the problem, take my sub to a new Excel document and create a textbox named "txt_1", that's all you need to run it.

如果有人知道为什么失败,请帮助!

If anyone has any idea why it fails, please help!

推荐答案

您需要定义下划线样式.最后一行 txt1.TextFrame.Characters.Font.Underline = xlUnderlineStyleSingle

You need to define the Underline style. Taking your last line txt1.TextFrame.Characters.Font.Underline = xlUnderlineStyleSingle

这篇关于文本框的下划线属性不能像其他样式一样工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆