【问题标题】:Selecting first alphabet in a word document选择word文档中的第一个字母
【发布时间】:2016-09-17 16:17:52
【问题描述】:

示例 -

“让这成为测试句”,假设这一行被选中,我需要一个 Word 宏来只选择第一个字母,即“L”,然后以我想要的任何方式格式化它...... 我无法让宏从所选行中仅选择第一个字母。 我试过这个 - `'Selection.HomeKey 单位:=wdLine

Selection.MoveDown 单位:=wdLine,计数:=1

Selection.Expand wdLine

MsgBox (Selection.Text)`

谁能给我一个答案

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    我假设你的意思是选择中的第一个字符?

    MsgBox Selection.Characters(1)
    

    或者,用它使那个字符加粗:

    Dim firstChar As Word.Range
    Set firstChar = Selection.Characters(1)
    firstChar.Bold = True
    

    【讨论】:

      【解决方案2】:
      Option Explicit
      
      Sub main()
          Dim firstAlphabet As Range
      
          Selection.SetRange Start:=0, End:=1 '<--| collapse Selection to its first character
      
          Set firstAlphabet = Selection.Range
          ' now use 'firstAlphabet ' range for your formatting
      
      
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-23
        • 1970-01-01
        相关资源
        最近更新 更多