The first line is what's highlighted
Sub ConvertSelection()
Dim CellWidth As Integer 'Characters per Cell in output file
Dim txt As String
Dim txt2 As String
Dim multicells As Integer
Dim RangeToUse As Range
Dim r As Object
Dim FileName As String
Dim i As Integer
Dim j As Integer
Dim pos As Integer
Dim convertDollar As Boolean
Dim booktabs As Boolean
Dim tableFloat As Boolean
Dim Indent As Integer
Dim Original As Range
Application.ScreenUpdating = False
CellWidth = Val(frmConvert.txtCellSize)
convertDollar = frmConvert.chkConvertDollar
booktabs = frmConvert.chkBooktabs
tableFloat = frmConvert.chkTableFloat
Indent = Val(frmConvert.txtIndent)
multicells = 0
Set Original = Selection
Set RangeToUse = moveSelection 'move range to working sheet
Range("a1").Select 'this is done to solve cosmetic problem. range is
re-selected at the end
TransferStylesTopLeft RangeToUse
FullText = Space(Indent) + "% Table generated by Excel2LaTeX from sheet '" +
ActiveSheet.name + "'" + vbLf
If tableFloat Then
AddText Space(Indent) + "\begin{table}[htbp]", True
Indent = Indent + 2
AddText Space(Indent) + "\centering", True
AddText Space(Indent) + "\caption{Add caption}", True
Indent = Indent + 2
End If
AddText Space(Indent) + "\begin{tabular}{"
If booktabs Then
AddText Replace(GetColumnsFormat(RangeToUse), "|", "")
Else
AddText GetColumnsFormat(RangeToUse)
End If
AddText "}", True
'Start checking top border
Set r = RangeToUse.Rows(1)
If booktabs Then
AddText Space(Indent) + "\addlinespace", True
AddText Space(Indent) + "\toprule", True
Else
AddText HorizontalBorder(r.Borders(xlTop).LineStyle, Indent)
End If
'Table contents:
For j = 1 To RangeToUse.Rows.Count ' for each row
Set r = RangeToUse.Rows(j)
If (j = 2) And booktabs Then
AddText Space(Indent) + "\midrule", True
End If
AddText Space(Indent)
For i = 1 To r.Cells.Count ' for each cell in row r
' If multicells > 1 Then ' is this cell part of a multicolumn cell
' multicells = multicells - 1
' GoTo nxt
' End If
txt = r.Cells(i).Text
'Check for special characters % and $
If convertDollar Then
txt = Replace(txt, "\", "\textbackslash ")
txt = Replace(txt, "$", "\$")
txt = Replace(txt, "_", "\_")
txt = Replace(txt, "^", "\^")
End If
txt = Replace(txt, "%", "\%")
txt = Replace(txt, "&", "\&")
txt = Replace(txt, "#", "\#")
'Check for Font Styles
If r.Cells(i).Font.Bold Then txt = "{\bf " + txt + "}"
If r.Cells(i).Font.Italic Then txt = "{\it " + txt + "}"
'Check for multicolumns
If r.Cells(i).MergeCells Then 'multicolumn cell
multicells = r.Cells(i).MergeArea.Columns.Count
txt2 = "\multicolumn{" + Str(multicells) + _
"}{" + GetColumnsFormat(r.Cells(i))
txt2 = txt2 + "}{" + txt + "}"
AddText txt2
If i
AddText PadSpace(multicells * (3 + CellWidth) - 3 - Len(txt2))
End If
i = i + multicells - 1
Else 'single cell
AddText txt
If i
AddText PadSpace(CellWidth - Len(txt))
End If
End If
If i r.Cells.Count Then
AddText " & "
End If
Next i 'cells in row
AddText " \\", True
' Check for Border lines
If Not booktabs Then
AddText HorizontalBorder(r.Borders(xlBottom).LineStyle, Indent)
End If
Next j 'row
theend: 'Tabellenende
If booktabs Then
AddText Space(Indent) + "\bottomrule", True
End If
AddText Space(Indent) + "\end{tabular}"
If tableFloat Then
Indent = Indent - 2
AddText "", True
AddText Space(Indent) + "\label{tab:addlabel}