tdとかtrを書くの面倒なので作った。
以下を実行するとエクセルシートの選択範囲をテーブル用HTMLに書き換える。直接セルを書き換えてしまうので注意。
ファイル保存してから実行、もしくは実行後に下の削除用を実行。
' tableタグくらいは自分で書く。 Sub HTMLテーブル作成テスト() Dim r As Range For Each r In Selection If r.Row = Selection(1).Row Then ' 1行目は<th> r.Value = "<th>" & r.Value & "</th>" Else ' 2行目以降<td> r.Value = "<td>" & r.Value & "</td>" End If Next For Each r In Selection If r.Column = Selection(1).Column Then ' 1列目 r.Value = "<tr>" & r.Value ElseIf r.Column = Selection(Selection.Count).Column Then ' 最終列 r.Value = r.Value & "</tr>" End If Next End Sub ' タグ削除用 Sub deleteTag() Dim r As Range For Each r In Selection r.Value = Replace(r.Value, "<th>", "") r.Value = Replace(r.Value, "</th>", "") r.Value = Replace(r.Value, "<tr>", "") r.Value = Replace(r.Value, "</tr>", "") r.Value = Replace(r.Value, "<td>", "") r.Value = Replace(r.Value, "</td>", "") Next End Sub
選択範囲の上下左右四隅の考え方とかVBA教材向けのような気がする。
以上。