在excel VBA中,如何检索单元格内的文本格式 [英] in excel VBA, how to retrieve the formats of text within a cell

查看:165
本文介绍了在excel VBA中,如何检索单元格内的文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Excel VBA, I want to retrieve the text of a cell together with the format of each word. For example, Cell A1 has value "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 >". What is that object in Excel DOM?

推荐答案

您可以通过检查 Font c>字符,逐个打开/关闭格式化标签:

You can do so by examining Font of Characters, one by one, and opening/closing formatting tags in your output accordingly:

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

这篇关于在excel VBA中,如何检索单元格内的文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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