Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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
Performance excel-格式化html数据并回写到同一单元格-性能问题_Performance_Excel_Vba - Fatal编程技术网

Performance excel-格式化html数据并回写到同一单元格-性能问题

Performance excel-格式化html数据并回写到同一单元格-性能问题,performance,excel,vba,Performance,Excel,Vba,我有一个excel,其中a列包含未格式化的html数据。要格式化此数据,我将执行以下步骤: 1从第一个单元格中获取未格式化的html数据,并将其粘贴到Internet explorer上,然后将html页面中的格式化文本粘贴到excel E列 2从excel列E中,从每一行到最后一行读取数据,并粘贴到原始单元格中,保留格式,我使用下面的代码 Sub ConcatenateRichText(Target As Range, Source As Range) Dim Cell As Rang

我有一个excel,其中a列包含未格式化的html数据。要格式化此数据,我将执行以下步骤:

1从第一个单元格中获取未格式化的html数据,并将其粘贴到Internet explorer上,然后将html页面中的格式化文本粘贴到excel E列

2从excel列E中,从每一行到最后一行读取数据,并粘贴到原始单元格中,保留格式,我使用下面的代码

Sub ConcatenateRichText(Target As Range, Source As Range)
    Dim Cell As Range
    Dim i As Long
    Dim c As Long
    i = 1
    With Target
        .Clear
        For Each Cell In Source
            .Value = .Value & vbLf & Cell.Value
        Next Cell
        .Value = Trim(.Value)
    End With
    For Each Cell In Source
        For c = 1 To Len(Cell.Value)
            With Target.Characters(i, 1).Font
                .Name = Cell.Characters(c, 1).Font.Name
                .FontStyle = Cell.Characters(c, 1).Font.FontStyle
                .Size = Cell.Characters(c, 1).Font.Size
                .Strikethrough = Cell.Characters(c, 1).Font.Strikethrough
                .Superscript = Cell.Characters(c, 1).Font.Superscript
                .Subscript = Cell.Characters(c, 1).Font.Subscript
                .OutlineFont = Cell.Characters(c, 1).Font.OutlineFont
                .Shadow = Cell.Characters(c, 1).Font.Shadow
                .Underline = Cell.Characters(c, 1).Font.Underline
                .ColorIndex = Cell.Characters(c, 1).Font.ColorIndex
            End With
            i = i + 1
        Next c
        i = i + 1
    Next Cell
End Sub
问题是这段代码需要太多的时间来格式化数据,对于54行来说,它几乎需要10分钟

有没有更好的解决办法

这里是完整代码的链接

提前谢谢


注意:在上发布了相同的问题。如果我得到任何答案,我将在此更新

您需要显示完整的代码以进行判断。我想你可能每次都会打开互联网应用程序,这既费时又不必要。您的子例程中是否将Application.ScreenUpdate设置为false。。。谢谢KazJaw,这里是完整的代码:首先,您在子程序中使用了很多不推荐的选择方法。这里有一些问答,所以你可以找到避免的方法。事实上,选择是很费时的。第二,在主sub的最开始添加一行:“Application.ScreenUpdating=false”,并在完成MsgBox之前将其设置回true。我想这两个建议都会有帮助…@javanob,你能证实@KazJaw的建议是否有帮助吗?例如,如果将pastebin代码的第7行和第8行连接到ColumnsA:AB.NumberFormat=General,并且在任何地方都这样做。选择,您肯定会注意到改进。如果是的话,你能把问题标记为已回答吗?