Sub RunFile(FileName, FilePath) Dim MATLAB, Result, Command, MATLABWasNotRunning ''''''''''''''''''''''''''''''''''''''''''''''''''' ' Set Up ''''''''''''''''''''''''''''''''''''''''''''''''''' ' Connect to the automation server. ' MATLAB becomes a MATLAB handle to the running instance of MATLAB. On Error Resume Next ' Defer error trapping MATLAB = GetObject(, "matlab.application") If Err.Number <> 0 Then MATLABWasNotRunning = True Set MATLAB = CreateObject("matlab.application") Err.Clear ' Clear Err object in case error occurred. End If ''''''''''''''''''''''''''''''''''''''''''''''''''' ' Do the Work ''''''''''''''''''''''''''''''''''''''''''''''''''' If Not IsMissing(FilePath) And Not FilePath = "" Then Command = "cd('" + FilePath + "')" Result = MATLAB.Execute(Command) End If Command = FileName Result = MATLAB.Execute(Command) MsgBox("Done.") 'Result = MATLAB.Execute("waitforbuttonpress") End Sub set arg=wscript.arguments Dim codepath codepath="C:\Documents and Settings\fass\My Documents\Teaching\350\Matlab" Call RunFile(arg(0), codepath) 'Call RunFile(arg(0))