I have problem. I don’t know what is the code to call Matlab by using VBA excel.
I tried using
matlabinit
But after I run it, it doesn’t work and there was an error message "sub or function not defined“
ouh guys, i have this code, but i cannot run it.
Sub jadwal()
'*************************************************************
'Unprotect sheets
'*************************************************************
Sheets("Hasil_jadwal_baru").Select
ActiveSheet.Unprotect
'*************************************************************
'Clear the previous schedule
'*************************************************************
Sheets("Hasil_jadwal_baru").Select
Range("A1:CG14").Select
Selection.ClearContents
'*************************************************************
'Clear the previous variable in MATLAB and set up the application
'*************************************************************
Application.DisplayAlerts = False
Application.Run "matlabinit"
MLEvalString "clear;"
MLEvalString "clc;"
'*************************************************************
'Send input to MATLAB
'*************************************************************
MLPutMatrix "ic_april", Range("ic_april")
MLPutMatrix "ic_juni", Range("ic_juni")
MLPutMatrix "ic_sept", Range("ic_sept")
MLPutMatrix "ic_libur_april", Range("ic_libur_april")
MLPutMatrix "ic_libur_juni", Range("ic_libur_juni")
MLPutMatrix "ic_libur_sept", Range("ic_libur_sept")
'*************************************************************
'Solve the problem via MATLAB and LP-SOLVE
'*************************************************************
MLEvalString "fixuntukmin"
'*************************************************************
'Send the result to EXCEL
'*************************************************************
MLGetMatrix "hasil_jadwal", "Hasil_jadwal_baru"
MatlabRequest
'*************************************************************
'Close MATLAB
'*************************************************************
MLClose
MLAutoStart "no"
Application.DisplayAlerts = True
'*************************************************************
'Finish Alarm
'*************************************************************
'*************************************************************
'Reprotect sheets
'*************************************************************
Sheets("Hasil_jadwal_baru").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
End Sub
can you help me??
It sounds like you just need to add a reference to Spreadsheet link EX in your VBA code. Select tools -> references and then tick the spreadsheet link EX library. After that it should work.
Alternately you can call addin functions without adding references using application.run. So try
application.run "matlabinit". But I think in this case adding a reference is preferable as you are unlikely to be distributing a spreadsheet calling matlab.Also have you made sure the addin is installed? In excel 2010 click on the developer tab, choose addins (with the big gold gear icon) and tick the Spreadsheet Link Ex Ver… for use with Matlab. Then go into VBA and add the reference as described above.