Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 遍历Excel VBA对象属性_Html_Excel_Richtext_Strikethrough_Vba - Fatal编程技术网

Html 遍历Excel VBA对象属性

Html 遍历Excel VBA对象属性,html,excel,richtext,strikethrough,vba,Html,Excel,Richtext,Strikethrough,Vba,我在Excel中编写了以下VBA函数,用于将Excel单元格内容从混合格式转换为HTML。下面是我想转换的一个单元格的示例: 粗体字体、斜体、普通、上标和删除线: •第1行及更多 •第2行…lorem ipsum •第3行 我想要这样的输出: <b>Bold</b> type, <i>italics</i> type, plain type, <sup>super</sup>script and strike:<br&

我在Excel中编写了以下VBA函数,用于将Excel单元格内容从混合格式转换为HTML。下面是我想转换的一个单元格的示例:

粗体字体、斜体、普通、上标和删除线:
•第1行及更多
•第2行…lorem ipsum
•第3行

我想要这样的输出:

<b>Bold</b> type, <i>italics</i> type, plain type, <sup>super</sup>script and strike:<br>
&bull; Line 1 <b>& more</b><br>
&bull; Line 2… lorem <i>ipsum</i><br>
&bull; Line 3<br>

你可能明白了。谢谢你的意见。我搜索过的任何内容都不能帮助我完成这个变量属性引用。

我找到了关于使用
CallByName
的内容,但当我使用Characters类时,它会中断。因为我需要计算单元格中的每个字符,看起来
CallByName
没有帮助。没有任何人的评论或建议吗?我发现这个脚本需要很长时间才能运行——每个单元格需要几秒钟,所以在一个只有30行的列中,需要几分钟才能完成。使用静态变量会有任何帮助吗?
Public Function ConvertToHTML(cell As Range)
'Find formatted text in a cell and enclose in HTML formatting tags
Dim strHTML, HTMLTag(3, 4), HTMLChar(2, 2) As String
Dim i As Integer

'Define searchable font properties that convert to HTML tags
HTMLTag(1, 1) = "bold" 'Font property name
HTMLTag(1, 2) = "<b>"  'HTML opening tag
HTMLTag(1, 3) = "</b>" 'HTML closing tag
HTMLTag(1, 4) = False  'Property flag
HTMLTag(2, 1) = "italic"
HTMLTag(2, 2) = "<i>"
HTMLTag(2, 3) = "</i>"
HTMLTag(3, 4) = False
HTMLTag(3, 1) = "superscript"
HTMLTag(3, 2) = "<sup>"
HTMLTag(3, 3) = "</sup>"
HTMLTag(3, 4) = False

'Define searchable characters that convert to HTML tags
HTMLChar(1, 1) = "•"
HTMLChar(1, 2) = "&bull;"
HTMLChar(2, 1) = Chr(10)
HTMLChar(2, 2) = "<br>" & Chr(10)

'Iterate through each character in cell
For i = 1 To Len(cell)
    With cell.Characters(i, 1)
        'Iterate through each font property (on or off)
        'Check if property has changed

        If Not (.Font.Strikethrough) Then 'If character has strikethrough, skip it

            'Add opening tags
            'Check if Bold state has changed
            If ((.Font.Bold <> HTMLTag(1, 4)) And .Font.Bold) Then
                'Add opening tag and set flag to match
                strHTML = strHTML & HTMLTag(1, 2)
                HTMLTag(1, 4) = .Font.Bold
            End If

            'Check if Italic state has changed
            If ((.Font.Italic <> HTMLTag(2, 4)) And .Font.Italic) Then
                'Add opening tag and set flag to match
                strHTML = strHTML & HTMLTag(2, 2)
                HTMLTag(2, 4) = .Font.Italic
            End If

            'Check if Superscript state has changed
            If ((.Font.Superscript <> HTMLTag(3, 4)) And .Font.Superscript) Then
                'Add opening tag and set flag to match
                strHTML = strHTML & HTMLTag(3, 2)
                HTMLTag(3, 4) = .Font.Superscript
            End If

            'Add closing tags
            If ((.Font.Superscript <> HTMLTag(3, 4)) And Not (.Font.Superscript)) Then
                'Add opening tag and set flag to match
                strHTML = strHTML & HTMLTag(3, 3)
                HTMLTag(3, 4) = .Font.Superscript
            End If

            If ((.Font.Italic <> HTMLTag(2, 4)) And Not (.Font.Italic)) Then
                'Add opening tag and set flag to match
                strHTML = strHTML & HTMLTag(2, 3)
                HTMLTag(2, 4) = .Font.Italic
            End If

            If ((.Font.Bold <> HTMLTag(1, 4)) And Not (.Font.Bold)) Then
                'Add opening tag and set flag to match
                strHTML = strHTML & HTMLTag(1, 3)
                HTMLTag(1, 4) = .Font.Bold
            End If

            'Append current character
            strHTML = strHTML & .Text
        End If
    End With
Next i
'Return fully converted text
ConvertToHTML = strHTML

'Do character replacement for HTML compatibility
For i = LBound(HTMLChar) To UBound(HTMLChar)
    strHTML = Replace(strHTML, HTMLChar(i, 1), HTMLChar(i, 2))
Next i

ConvertToHTML = strHTML

End Function
.Font.(HTMLTag(i,4)) 'to reference Bold, Italic, Superscript member in Font
.Font.Properties(HTMLTag(i,4))
If clxnOfFont[i].name = HTMLTag(i,4) Then ...