首页 文章

在excel VBA中,如何检索单元格中的文本格式

提问于
浏览
2

在Excel VBA中,我想要检索单元格的文本以及每个单词的格式 . 例如,单元格A1的值为“sample text ". The Range(" A1 ").Value property only returns the plain text (i.e. " sample text "). What I want is an object that gives me something like " <i> sample </ i> <b> text </ b>” . Excel DOM中的那个对象是什么?

1 回答

  • 2

    您可以通过逐个检查 CharactersCharacters 并相应地打开/关闭输出中的格式化标记来执行此操作:

    dim i as long
    for i=1 to activecell.characters.count
      with activecell.characters(i,1).font
        if .bold then
          'open <b>, if not already opened
        else
          'close <b>, if not already closed
        end if
    
        if .italic then
          'open <i>, if not already opened
        else
          'close <i>, if not already closed
        end if
    
        ' etc
      end with
    next
    

相关问题