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

在Excel VBA中,我想要检索单元格的文本以及每个单词的格式。 例如,单元格A1具有“ 示例 文本 ”的值。 Range(“A1”)。Value属性只返回纯文本(即“示例文本”)。 我想要的是一个对象,它给了我一些像“</ i> <b>文本</ b>”的东西。 Excel DOM中的对象是什么?

您可以通过逐字检查Characters Font ,并相应地在输出中打开/closures格式化标记来完成此操作:

 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