0

基本上我想创建宏来获取单元格内容并放入 HTML 段落标签,但是如果单元格包含新行符号以将新行放入新标签中。有人可以帮我做或提供给我吗?提前致谢。

不正确:

<html>
<head>
    <title>example</title>
</head>
<body>
    <p>1
       2
       3</p>
</body>
</html>

正确的:

<html>
<head>
    <title>example</title>
</head>
<body> 
    <p>1</p>
    <p>2</p>
    <p>3</p>
</body>
</html>
4

1 回答 1

0

I've found a solution.

Sub lf2html()

Dim i, chrCount As Integer
Dim htmlTxt As String
Dim cell As Range
Dim SetCellStart
Dim SetCellStop

SetCellStart = InputBox("StartCell ( f0r example: a1 ):", "Enter number!")
SetCellStop = InputBox("StopCell ( f0r example: a2 )", "Enter number!")

'MsgBox SetCellStart SetCellStop
For Each cell In Range(SetCellStart, SetCellStop)
    htmlTxt = "<html><head></head><body><p>"
        chrCount = cell.Characters.Count

        For i = 1 To chrCount
            With cell.Characters(i, 1)
                If (Asc(.Text) = 10) Then
                    htmlTxt = htmlTxt & "</p><p>"
                Else
                    htmlTxt = htmlTxt & .Text
                End If
            End With
        Next

    htmlTxt = htmlTxt & "</p></body></html>"
    cell.Value = htmlTxt
Next cell

End Sub
于 2013-08-22T10:46:09.503 回答