2013-08-21 2 views
0

기본적으로 셀 내용을 가져 와서 HTML 단락 태그를 넣으려는 매크로를 만들고 싶지만 셀에 새 줄을 추가하여 새 줄에 새 줄 기호가 있으면. 누군가 나를 도와 주거나 나에게 그것을 제공 할 수 있습니까? 미리 감사드립니다.EXCEL의 셀 내용을 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> 

답변

0

나는 해결책을 발견했습니다.

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 
관련 문제