フィルターのクリア

How to change the path when using VBA macro to run .m file

5 ビュー (過去 30 日間)
Surae
Surae 2011 年 7 月 19 日
Hi,
I'm trying to write VBA macros to run m file on a desired folder while calling Matlab.
The folder path located the m file is "C:\Documents and Settings\M02043\Desktop\Test".
However, I always get a default path, "C:\Program Files\MATLAB\R2008b", so I can't run the m file from this.
Do you have any idea how I can set the path I wanted when using VBA macro to run .m file.
Matlab version: R2008b (7.70)
VBA macors:
Sub Macro()
Dim MatLab As Object
Dim Result As String
Set MatLab = CreateObject("MatLab.desktop.Application")
Call MatLab.Execute("cd C:\Documents and Settings\M02043\Desktop\Test")
Result = MatLab.Execute("f_ann")
End Sub

回答 (2 件)

Kaustubha Govind
Kaustubha Govind 2011 年 7 月 19 日
You need:
Call MatLab.Execute("cd 'C:\Documents and Settings\M02043\Desktop\Test'")
The CD command doesn't like spaces in the directory path - you need single quotes around it.

Surae
Surae 2011 年 7 月 19 日
I solved this issue with following macros. The problem was just CD command :)
Sub Macro()
Dim MatLab As Object
Dim Result As String
Set MatLab = CreateObject("MatLab.desktop.Application")
Result = MatLab.Execute("cd('C:\Documents and Settings\M02043\Desktop\MATLAB Interface Test')")
Result = MatLab.Execute("f_ann")
End Sub
thanks a lot.

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by