2012-04-05 20 views
4

HTML変換からExcel変換に至るまで、私はうまくいきました。私が与えられたサンプルマクロコードは、コードをHTML形式からExcelセルに変換する素晴らしい仕事でした(Siddharth Rout!に感謝します)。私が今実行している問題は、IEオブジェクトが段落、改行、およびExcelのリスト項目をどのように処理するかとは関係ありません。 p、br、liは元のセルの下のセルにテキストを移動し、そのセルにあったデータを上書きします。 HTMLのブロックを1つのセルだけに表示する方法はありますか?つまり、新しい行タグがあれば、同じセルに新しい行が作成されます。HTMLをExcelの書式変換に変換する - 同じセルに改行と改行を挿入する

VBAコード

Sub Sample() 
    Dim Ie As Object 

    Set Ie = CreateObject("InternetExplorer.Application") 

    With Ie 
     .Visible = False 

     .Navigate "about:blank" 

     .document.body.InnerHTML = Sheets("Sheet1").Range("A1").Value 

     .document.body.createtextrange.execCommand "Copy" 
     ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1") 

     .Quit 
    End With 
End Sub 

サンプルHTML

<p> Here are some possible uses:</p> <ul> <li><font color = "red"> syntax highlighting code snippets</font></li> <li style ="font-weight:bold; color: orange">validating credit card numbers, phone numbers, and zip codes</li> <li style = "font-style: italic">styling email addresses and tags</li> </ul> 

複数の行に表示されるサンプル出力(一つのセルに複数行に表示したい - と同様道順+入力が働く)

Here are some possible uses: 



syntax highlighting code snippets 

**validating credit card numbers, phone numbers, and zip codes** 

*styling email addresses and tags* 

答えて

1

私はあなたがそれを行うことができるかわかりません(私は間違っている可能性があります)。一時シートに貼り付けた後、それらの行と挿入をコピーし、代わりに、同じシートに貼り付け、それをする:それは、その後ここに上書きされるデータのちょうど問題がある場合でも、代替:)

ロジックですをsheet1に入れて、データを上書きしないようにします。スナップショットを参照してください。

SNAPSHOT:

enter image description here

CODE:

Sub Sample() 
    Dim ws As Worksheet, wstemp As Worksheet 
    Dim Ie As Object 
    Dim LastRow As Long 

    Set Ie = CreateObject("InternetExplorer.Application") 

    Set ws = Sheets("Sheet1") 

    '~~> Create Temp Sheet 
    Set wstemp = Sheets.Add 

    With Ie 
     .Visible = True 

     .Navigate "about:blank" 

     '~~> I am assuming that the data is in Cell A1 
     .document.body.InnerHTML = ws.Range("A1").Value 

     '~~> Deleting the row which had the html string. I am assuming that it was in Row 1 
     ws.Rows(1).Delete 

     .document.body.createtextrange.execCommand "Copy" 
     wstemp.Paste Destination:=wstemp.Range("A1") 

     '~~> Find the last row in the temp sheet 
     LastRow = wstemp.Cells.Find(What:="*", After:=wstemp.Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row 

     '~~> Copy that data 
     wstemp.Rows("1:" & LastRow).Copy 

     '~~> insert it in Sheet1 
     ws.Rows(1).Insert Shift:=xlDown 

     .Quit 
    End With 

    '~~> Delete Temp sheet 
    Application.DisplayAlerts = False 
    wstemp.Delete 
    Application.DisplayAlerts = True 

End Sub 

HTH

関連する問題