2014-09-26 45 views
0
Private Sub CommandButton1_Click() 

    Dim MatLab As Object 
    Set MatLab = CreateObject("Matlab.Application") 
    MatLab.Execute ("a = 1") 
    MatLab.Execute ("disp(a)") 

End Sub 

我需要顯示的值MATLAB變量「a」在MATLAB和顯示窗口應該是我看到,檢查命令是否執行或者不執行?我怎樣才能打開使用VBA語句

回答

0

一種方法是在MATLAB中編寫代碼,並使用VBA作爲shell來執行該功能。

在VBA中,您可以像這樣使用shell

shell "C:\Matlab2011a\matlab.exe -r your_function_name 

,並在你的Matlab代碼

function yourFunction() 
    cd('C:\yourDirectory'); % moves you to your desired directory 
          % your code here 
    exit;     % exits Matlab 
end 

方法二:

您可以使用SpreadSheet Link EX並呼籲matlabinit功能。