Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
xlsread when calling Matlab executable from VBA

Subject: xlsread when calling Matlab executable from VBA

From: Alaa Elwany

Date: 7 Jan, 2012 23:00:10

Message: 1 of 1

Hi,

I generated an executable file from an m code using deploy tool, named (Myfile.exe). I call this executable from Excel VBA using the Shell Function.

The m code starts by importing some data from Excel:
xlsread('data.xlsx')

I have everything (the executable, the Excel file with the VBA code to call it) in one folder.

The Strange problem is:
I wrote the xlsread command as above without the file path, to make sure data is imported from the Excel file placed within the same folder regardless of where the folder is (to give flexibility for the user). When I run the executable by double clicking it, it works fine.

HOWEVER.. When I call the very same executable from VBA using the shell function, it halts and tells me:
-->Error using xlsread
--> File C:\Users\elwany\Documents\data.xlsx not found

1. Why does the executable go and search for the Excel file in that file path ?! Is it a setting within Matlab or Excel VBA?
2. Why does the executable search for the Excel file in that path when I call it from VBA, but searches for the Excel file in the same folder when I double click the executable??

Am I messing out something in Matlab or VBA? I am guessing VBA, but I might be wrong.

For reference, the VBA code I use to call the executable is:

Sub Clean()
  On Error Resume Next
  Shell ("Myfile.exe")
  If Err <> 0 Then
      MsgBox "Can't start the application.", vbCritical, "Error"
  End If
End Sub

Thank you very much in advance,

Alaa

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us