Skip to content

Instantly share code, notes, and snippets.

@hamaguchi-amago
Created September 10, 2019 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamaguchi-amago/2728d090a52cc5bdab65384ef31cb6da to your computer and use it in GitHub Desktop.
Save hamaguchi-amago/2728d090a52cc5bdab65384ef31cb6da to your computer and use it in GitHub Desktop.
HTML変換処理
Attribute VB_Name = "Module1"
Sub ファイル出力()
Attribute ファイル出力.VB_Description = "定義書用のマクロを出力する"
Attribute ファイル出力.VB_ProcData.VB_Invoke_Func = "O\n14"
'
' ファイル出力 Macro
' 定義書用のマクロを出力する
'
' Keyboard Shortcut: Ctrl+Shift+O
'
Dim ws As Worksheet
Set ws = ActiveSheet
Dim trs As String
Dim tds As String
Dim i As Long
i = 1
Do While ws.Cells(i, 1).value <> ""
Dim workTr As String
If i = 1 Then
workTr = "<tr style=""background-color: rgb(153 , 255 , 255)"">"
Else
workTr = "<tr>"
End If
tds = ""
Dim j As Long
For j = 1 To 15
Dim value As String
If ws.Cells(i, j).value = "" Then
value = ""
Else
value = ws.Cells(i, j).value
End If
tds = tds & "<td>" & value & "</td>"
Next j
trs = trs & workTr & tds & "</tr>"
i = i + 1
Loop
Dim datFile As String
datFile = ActiveWorkbook.Path & "\" & ws.Name & ".txt"
Open datFile For Output As #1
Print #1, "<table border=""1"" width=""100%"" style=""width: 100% ; height: 100% ; border-collapse: collapse""><tbody>" & trs & "</tbody></table>"
Close #1
MsgBox ws.Name & ".txt" & "に書き出しました"
End Sub
@hamaguchi-amago
Copy link
Author

ブログの記事で作成しました。
興味のある方はご覧ください。

Excelの表をhtmlに変換するツールをVBAで作ってみた
https://neko-py.com/excel-table-html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment