Excel2latex

D

didichou

Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I'm trying to convert a table to latex but there's an error message that pops up each time: Compile error: sub or function not defined.

What am I missing? The Excel2LaTeX.xla is in my Additional Tools folder and the macros are enabled. What more can I do?

Thanks,
 
J

John_McGhie_[MVP]

Why did you not tell us WHICH Sub or Function? Sorry, but we can't read
your screen from here!

That error means there is a piece missing from your macro.

When it occurs, the Visual Basic Environment should open, and the yellow
highlight will be resting on the offending line of code, which will be a
call to something that is not there.

You need to find out what that is, and replace it.

It may be that you are using VBA from a higher version of Excel which has
functions that 2004 does not have. In which case you will have to code
around the function.

If you tell us which one it is, we may be able to help.

If the VBE does not appear when the error occurs, you may be dealing with
password-protected code. Without the password, you can't go any further.

Hope this helps


Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I'm
trying to convert a table to latex but there's an error message that pops up
each time: Compile error: sub or function not defined.

What am I missing? The Excel2LaTeX.xla is in my Additional Tools folder and
the macros are enabled. What more can I do?

Thanks,

--

The email below is my business email -- Please do not email me about forum
matters unless I ask you to; or unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410 | mailto:[email protected]
 
B

Bob Greenblatt

Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel
I'm trying to convert a table to latex but there's an error message that
pops up each time: Compile error: sub or function not defined.

What am I missing? The Excel2LaTeX.xla is in my Additional Tools folder
and the macros are enabled. What more can I do?

Thanks,
I do not know what Latex is, but I'll bet a whole lot that the authors
of the addin did not allow for the possibility that it may work on a
Mac. Your only alternative is to contact the authors and ask them to
rewrite the addin so it will work on a Mac. (or ask therm to contact me
and I will be happy to provide a quotation for the conversion.)
 
D

didichou

When the visual basic environment opens, it highlights the following line: Sub ConvertSelection(). I don't know how to code around that problem, so if you can help, it would be much appreciated!
 
B

Bob Greenblatt

When the visual basic environment opens, it highlights the following
line: Sub ConvertSelection(). I don't know how to code around that
problem, so if you can help, it would be much appreciated!
I don't have a clue unless I can see all the code to figure out what is
happening. Posting a single line does no good at all.
 
J

John_McGhie_[MVP]

Are you SURE it's that line?

That IS the "Sub or Function" that it says is not defined...

Can you post the whole of the code in that block, down to the End Sub
statement?

Sorry mate, but this is NOT Twitter: I can't help you unless you provide
full detail of what's going on. If you don't write a screenfull in here,
chances are, I don't have the details I need to help you solve your problem.

Cheers


When the visual basic environment opens, it highlights the following line: Sub
ConvertSelection(). I don't know how to code around that problem, so if you
can help, it would be much appreciated!

--

The email below is my business email -- Please do not email me about forum
matters unless I ask you to; or unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410 | mailto:[email protected]
 
B

Bob Greenblatt

OK, that is the comlete text of the sub, but I still can;t figure out
what is wrong as i don't know how this sub is called, its context in the
function, the global definitions etc.

If you really want help you need to post the ENTIRE add in code with a
full description of what is happening and what errors you get.

I still maintain tha the authors of this functin did not alow for it to
run on a Macintosh. They have probably used VB constructs that are OK in
Windows but not a Mac. You best bet is to contact them and explain that
is does not work and fins out their plans to correct it.
 
J

John_McGhie_[MVP]

I need the other part of that, we didn't get it all down to the "End Sub"

So far, I can tell you that the construct below is wrong:

'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


In each case where "If i" appears on a line by itself, there should be
something following it on that line, or the line is illegal in VBA. Those
lines throw a compile-time error here. That would produce your problem.

Send us the rest of it and we'll have another go.

Cheers


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}

--

The email below is my business email -- Please do not email me about forum
matters unless I ask you to; or unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410 | mailto:[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top