How can I open References to "excllink.xlam" in VBA

8 views (last 30 days)
How can I open References to "excllink.xlam" in VBA. It belongs to a Matlab example named" Exlisamp". When I want to open it in VBA it asks for password.

Answers (2)

Chidvi Modala
Chidvi Modala on 8 Mar 2021
It would be helpful if you can provide more details on the reproduction steps and the exact error you are facing. A screenshot of the error can be helpful. In the meanwhile you can refer to Work with Microsoft Visual Basic Editor section in https://www.mathworks.com/help/exlink/add-in-setup-1.html. This might help
  1 Comment
Marzieh Shafiei
Marzieh Shafiei on 8 Mar 2021
Thank you. I want to link excel to Matlab using VBA. I need to know the VBA codes that were used for the example " Exlisamp". Specifically, the codes written in VBA that automatically starts Matlab, send data, run matlab function and then recieves data. I am not familiar with VBA, so I though the codes in that example might be very helpful for me. When I check VBA codes for "Exlisamp" example, I can see the function for doing curvefitting. The below picture shows the function in module1. But I can not see the VBA codes corresponding for Matlab autostart and other codes that mentioned above.
Please kindly introduce me a tutorial, or documentation that I can find out how to use VBA for Running Matlab from Excel using VBA. I need VBA, because I need all the calculations be done automatically. and evetually, I use all of them for running an Aspen Plus simulation that connects to excel, then connects to Matlab and run a model.
Thank you very much.

Sign in to comment.


Chidvi Modala
Chidvi Modala on 8 Mar 2021
An example VBA code is the following:
Sub MyTest()
Dim m As Object
Dim output As Variant
Dim x As Long
x = 6
ReDim rors(1 To x, 1 To 1)
Set m = CreateObject("Matlab.Application")
m.Feval "randi", 1, output, 4, 1, 6
Set m = Nothing
For i = 0 To 5
rors(i + 1, 1) = output(0)(0, i)
Next i
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")
Set TxtRng = ws.Range("A1:A6")
TxtRng.Value = rors
End Sub
The routine above calls the "randi" MATLAB function.
The "1" indicates the number of outputs, "output" the variable where to store the output of the function call, and finally "4,1,6" are the inputs to the "randi" function.
The "output" variable is then copied over to "rors", and finally written to cells A1 to A6.
You can also refer to a similar question asked here

Categories

Find more on Data Export to MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!