I'm trying to automate a macro that converts an Excel table to LaTeX source code with another simple macro. Basically I don't want to use the userform, so I'm trying to call the button click of the desired output I want, but I'm having problems.
It is the Excel2Latex macro on ctan.org
Here is the main sub, as you can see my commented parts are all the different things I've been trying after searching for help.
Sub latex()
With NewController
Set .View = NewView
Set .Model = NewDefaultModel
Set .Storage = NewStorage
.Run
Application.Wait Now + TimeValue("00:00:02")
frmConvert.cmdSave.Object.Value = True
'UserForm2.CommandButton1.Object.Value = True
'frmConvert!cmdSave.SetFocus
'SendKeys "{Enter}"
'Call frmConvert.cmdCopy_Click
'Call frmConvert.cmdSv
'Call frmConvert.cmdCopy_Click
'Call Memento.SaveConversionResultToFile
'Application.Wait Now + TimeValue("00:00:03")
'Application.Run "frmConvert.cmdCopy_Click", txtResult
'frmConvert.cmdCopy = True
'frmConvert.cmdCopy = vbClick
'frm 'Application.Run frmConvert.cmdSave
'Call frmConvert.cmdCopy_Click
'frmConvert.cmdSave = vbClick
End With
End Sub
The code behind the button I want is a Private Sub
Private Sub cmdSave_Click()
SaveConversionResultToFile mModel
Hide
End Sub
When I try to call the cmdSave_Click sub it returns run time error 91, object variable or with block variable not set. I've tried setting the sub to Public too.
The most luck I've had so far is activating the copy to clipboard button on the userform, but it just copies the default text in the userform, not the LaTeX table that is generated in the window.
Any suggestions?
Public Sub SaveConversionResultToFile(ByVal pModel As IModel)
Dim sFileName As String
sFileName = pModel.AbsoluteFileName
If sFileName = "" Then Exit Sub
Open sFileName For Output As 1
Print #1, pModel.GetConversionResult;
Close #1
End Sub
I get the error on the sFileName = pModel.AbsoluteFileName
line in reference to MatthewD's question.
Sub
and then call it. – cyboashusFileName = pModel.AbsoluteFileName
check ifpModel
is nothing.Msgbox pModel Is Nothing
. What's the result? True or False? – cyboashupModel
first and then only you can access its propertyAbsoluteFileName
– cyboashu