I'm trying to use the code below to convert data in my worksheet to html. I tried pasting in visual basic, but when I highlight and run, I get an error (can't execute in break mode). Beginner, so please let me what I'm not doing here. Thank you!
My objective is to be able to convert cell data to html within the workbook. Example of cell data:
[TABLE="width: 320"]
<tbody>[TR]
[TD="width: 64"]Men's Sizes[/TD]
[TD="width: 64"]XS[/TD]
[TD="width: 64"]S[/TD]
[TD="width: 64"]M[/TD]
[TD="width: 64"]L[/TD]
[/TR]
[TR]
[TD]Size (Shirts & Tops)[/TD]
[TD]30/32-32/34[/TD]
[TD]34/36-36/38[/TD]
[TD]38/40-40/42[/TD]
[TD]42/44-44/46[/TD]
[/TR]
[TR]
[TD]Chest[/TD]
[TD]31"-33"[/TD]
[TD]34"-37"[/TD]
[TD]37"-40"[/TD]
[TD]40"-44"[/TD]
[/TR]
[TR]
[TD]Waist[/TD]
[TD]27"-29"[/TD]
[TD]30"-32"[/TD]
[TD]32"-35"[/TD]
[TD]35"-39"[/TD]
[/TR]
[TR]
[TD]Hip[/TD]
[TD]32"-43"[/TD]
[TD]35"-37"[/TD]
[TD]37"-40"[/TD]
[TD]40"-44"[/TD]
[/TR]
[TR]
[TD]Inseam[/TD]
[TD]31.9"[/TD]
[TD]32.1"[/TD]
[TD]32.3"[/TD]
[TD]32.5"[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Option Explicit
Sub ConvertToHTML()
Dim RowStart As Integer
Dim ColStart As Integer
Dim ColCount As Integer
Dim RowCount As Integer
Dim RowEnd As Integer
Dim ColEnd As Integer
Dim ctrRow As Integer
Dim ctrCol As Integer
Dim IndentString As String
Dim CellString As String
'Get Selection Location and Size
RowStart = Selection.Row
ColStart = Selection.Column
ColCount = Selection.Columns.Count
RowCount = Selection.Rows.Count
RowEnd = RowStart + RowCount - 1
ColEnd = ColStart + ColCount - 1
'Get Indent String
IndentString = Sheet1.TextBoxIndentSpaces.Text
'Start Table
Sheet1.TextBoxOutput.Text = IndentString + ""
'Make Table Cells
For ctrRow = RowStart To RowEnd
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
For ctrCol = ColStart To ColEnd
CellString = Sheet1.Cells(ctrRow, ctrCol).Text
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
Next ctrCol
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
Next ctrRow
'Close Table
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + "
<tbody>
</tbody>"
End Sub
My objective is to be able to convert cell data to html within the workbook. Example of cell data:
[TABLE="width: 320"]
<tbody>[TR]
[TD="width: 64"]Men's Sizes[/TD]
[TD="width: 64"]XS[/TD]
[TD="width: 64"]S[/TD]
[TD="width: 64"]M[/TD]
[TD="width: 64"]L[/TD]
[/TR]
[TR]
[TD]Size (Shirts & Tops)[/TD]
[TD]30/32-32/34[/TD]
[TD]34/36-36/38[/TD]
[TD]38/40-40/42[/TD]
[TD]42/44-44/46[/TD]
[/TR]
[TR]
[TD]Chest[/TD]
[TD]31"-33"[/TD]
[TD]34"-37"[/TD]
[TD]37"-40"[/TD]
[TD]40"-44"[/TD]
[/TR]
[TR]
[TD]Waist[/TD]
[TD]27"-29"[/TD]
[TD]30"-32"[/TD]
[TD]32"-35"[/TD]
[TD]35"-39"[/TD]
[/TR]
[TR]
[TD]Hip[/TD]
[TD]32"-43"[/TD]
[TD]35"-37"[/TD]
[TD]37"-40"[/TD]
[TD]40"-44"[/TD]
[/TR]
[TR]
[TD]Inseam[/TD]
[TD]31.9"[/TD]
[TD]32.1"[/TD]
[TD]32.3"[/TD]
[TD]32.5"[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Option Explicit
Sub ConvertToHTML()
Dim RowStart As Integer
Dim ColStart As Integer
Dim ColCount As Integer
Dim RowCount As Integer
Dim RowEnd As Integer
Dim ColEnd As Integer
Dim ctrRow As Integer
Dim ctrCol As Integer
Dim IndentString As String
Dim CellString As String
'Get Selection Location and Size
RowStart = Selection.Row
ColStart = Selection.Column
ColCount = Selection.Columns.Count
RowCount = Selection.Rows.Count
RowEnd = RowStart + RowCount - 1
ColEnd = ColStart + ColCount - 1
'Get Indent String
IndentString = Sheet1.TextBoxIndentSpaces.Text
'Start Table
Sheet1.TextBoxOutput.Text = IndentString + ""
'Make Table Cells
For ctrRow = RowStart To RowEnd
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
For ctrCol = ColStart To ColEnd
CellString = Sheet1.Cells(ctrRow, ctrCol).Text
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
Next ctrCol
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
Next ctrRow
'Close Table
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + "
" + CellString + " |
<tbody>
</tbody>
End Sub