Excelデータをhtmlで出力する際に改行するには?

解決


ハピろう  2013-03-09 17:01:41  No: 143451  IP: [192.*.*.*]

Excelデータをhtmlで出力する際に、D列のセルの文字列を改行してhtmlデータに表示させる方法を教えて下さい?
以下にコードを記載します。よろしくお願いします。


'メインのループ
Sub test001_main()

    Dim y As Integer  'ループのカウンター
    
    y = 4  '4行目から
    While Cells(y, "A") <> ""  'A列に何か入っている間ループ
        'ファイル作成のサブ関数に名前とファイル名を渡す
        Call test001_CreateHtmlFile(Cells(y, "B"), Cells(y, "C"), Cells(y, "D"), Cells(y, "E"), Cells(y, "F"), Cells(y, "G"), Cells(y, "H"), Cells(y, "I"), Cells(y, "J"), Cells(y, "K"), Cells(y, "L"), Cells(y, "M"), Cells(y, "N"), Cells(y, "O"), Cells(y, "P"), Cells(y, "Q"), Cells(y, "R"), Cells(y, "S"), Cells(y, "T"), Cells(y, "U"))
        y = y + 1
    Wend
    
    MsgBox "作成が終了しましたデータを確認してください"
    
End Sub

'名前とファイル名を受け取り、HTMLファイルを作成するサブ関数
Sub test001_CreateHtmlFile(strMei As String, strHTML As String, strCt As String, strDt As String, strEt As String, strFt As String, strGt As String, strHt As String, strIt As String, strJt As String, strKt As String, strLt As String, strMt As String, strNt As String, strOt As String, strPt As String, strQt As String, strRt As String, strSt As String, strTt As String)
    Dim strFNAME As String 'ファイル名格納用

    'ブックと同じ位置にxxx.htmlを作成する
    strFNAME = ThisWorkbook.Path & "\" & "INC-HR-" & strMei & ".html" 'ファイル名の作成
    Open strFNAME For Output As #1 'ファイル番号1で新規作成

    'データ書き込み、名前だけ変えて作成する
    Print #1, "<html>"
    Print #1, "<head>"
    Print #1, "<title>" & strMei & "</title>"
    Print #1, "</head>"
    Print #1, "<body>"
    Print #1, "<h1>" & "INC-HR-" & strMei & "</h1>"
    Print #1, "Range("; B1; ")" & strMei & "<br>"
    Print #1, "Range("; C1; ")" & strHTML & "<br>"
    Print #1, "Range("; D1; ")" & Replace(strCt, vbCrLf, "<br>") & "<br>"
    Print #1, ""
    Print #1, ""
    Print #1, "</body>"
    Print #1, "</html>"
    
    Close #1  '開いたら閉じようね

End Sub

編集 削除
takana  2013-03-20 18:09:31  No: 143452  IP: [192.*.*.*]

Replace(strCt, vbCrLf, "<br>")

Replace(strCt, vbLf, "<br>")
に変更すれば?

編集 削除
ハピろう  2013-03-20 21:19:38  No: 143453  IP: [192.*.*.*]

takanaさん

本当にどうもありがとうございました。
ご教示いただいた方法で解決しました。
ご回答いただき、感謝いたします。

編集 削除