2016-07-15 12 views
0

我只是想在工作表文本框中使用VBA將特定字符中的某些文本強調爲另一個文本。它應該是非常簡單的,我可以做到沒有問題與粗體和斜體。文本框的下劃線屬性不能像其他文件一樣工作

我就上線,這是非常奇怪的,因爲它工作了前面2條線以下子

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)表示「不可能定義字體屬性的下劃線」功能。

要重新創建問題,請將我的子文件添加到新的Excel文檔中,並創建一個名爲「txt_1」的文本框,這就是運行它所需的全部內容。

如果有人有任何想法,爲什麼它失敗,請幫助!

+0

http://answers.microsoft.com/en-us/office/forum/office_2007-access/underline-specific-words-in-text-box/cf2bf9ac-a1f3-42bf-a51e -f530ae907a06?auth = 1這對你有幫助嗎? –

回答

3

使用TextFrame2爲下劃線

txt1.TextFrame2.TextRange.Font.UnderlineStyle = msoUnderlineSingleLine

+0

如果你想獲得真正的花式,'TextFrame2'給你更多的在線樣式。 :) – cyboashu

5

您需要定義下劃線樣式。以你的最後一行 txt1.TextFrame.Characters.Font.Underline = xlUnderlineStyleSingle

+0

啊..我現在覺得自己像個小菜鳥:) –

+0

這是其他風格的鏈接:https://msdn.microsoft.com/en-us/library/office/aa215913%28v=office.11​​%29。 ASPX – Tim