?
Solved

modify built-in matlab mex file

Posted on 2010-08-25
10
Medium Priority
?
788 Views
Last Modified: 2016-03-02
Hey-- I am attempting to automatically open an excel workbook with Matlab code that has macros running automatically when it opens via an Auto_Open sub in VBA. When I use:

exlWkbk = Excel1.Workbooks;
exlFile = exlWkbk.Open('filename.xls')

Excel opens with the macros enabled, but the macros do not automatically run upon opening despite being in the Auto_Open sub, and I am also unable to change the Macro Security level on my computer. I noticed that if I use the Matlab winopen function to open the workbook, however, it prompts me to click disable or enable macros, and when I click enable, it opens and the Auto_Open macros do automatically run.

My idea was to open it with winopen and then write code to programmatically select enable from the prompt, which I've been able to do via Sendkeys code in VB which I've saved as a .vbs file... I am able to call it in Matlab and it does successfully click enable and get through the prompt. The problem is, I have to call winopen to get to the prompt and then call vbs to get through it, and winopen does not stop executing until the prompt is already clicked out of... Since Matlab is open-source my new idea was to modify winopen so that it just stops executing right when it gets to the prompt so taht the vbs file can then be executed to do it, but while winopen is an open-source m-file, it seems to use a helper win_open_mex function that is a Matlab mex file. I figured I could modify the C code in the mex file and go from there, but I'm unable to access the mex code... I open it in Notepad, WordPad, Word, etc and it's all just giberish...

Is there any way to either access the win_open_mex code to modify it, or to approach the whole thing any other way that may work better and be easier??

I really appreciate your help.
0
Comment
Question by:Jeff9687
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 6

Expert Comment

by:LeeeRussell
ID: 33529039
I have to say that I'm struggling to understand what your question is.  You seem to be trying to solve a problem that's arisen because you're trying to solve a different problem.

I think your real issue is how to open an excel file with macros enabled, but, as I said, I'm struggling to say that for certain.

I strongly suggest that you either restate your original issue here, without all the references to Matlab or ask a new question that only states your original issue.
0
 

Author Comment

by:Jeff9687
ID: 33532709
Hey-- yeah, I'm sorry... I do understand how the original post could come off as a little convoluted! Let me try to clarify the whole situation:

ORIGINAL ISSUE: I need to write Matlab code that automatically opens an Excel workbook. The workbook has macros in an auto_open sub, and when the Matlab code opens the workbook, the macros in auto_open need to automatically run.

Secondary problem: Workbooks.open in Matlab doesn't seem able to do this because of Excel macro security settings that I'm not allowed to change on my computer. Winopen opens the workbook, but the user is prompted to click "Enable macros"... afterwards, once "enable macros" is clicked in the prompt the macros in auto_open do run, but I need "Enable macros" to be automatically clicked, which I do via a vbs file using SendKeys that I call in Matlab. The problem is, I can't call the vbs file in Matlab until winopen is finished executing, and winopen doesn't stop executing until the prompt is already clicked out of and the workbook opens... my approach was to modify winopen since Matlab is open source so that it just stops once it gets to the prompt, but it includes a built-in mex file win_open_mex that I can't seem to access.

I hope this clarifies things... I'm really kind of stuck!
0
 
LVL 6

Expert Comment

by:LeeeRussell
ID: 33532744
When you open the Excel spreadsheet directly (not from Matlab) do you have to click on "Enable macros"?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jeff9687
ID: 33532803
Yes, because the Macro Security level in the workbook is set to Medium... if it were set to low then there would be no prompt and it would automatically open with the macros enabled, but I am not allowed to change the security level on my computer.
0
 
LVL 6

Expert Comment

by:LeeeRussell
ID: 33532901
There's a couple of other things you could try then I suppose.

Is there any chance you could contact your IT department and let you change the security level on you computer?

Have you thought about running something like an AutoIT script from Matlab?  You could write a script in AutoIT that would load the excel file and then press the enable macros button?  This doesn't sound much less convoluted than the method you were trying though.
0
 

Author Comment

by:Jeff9687
ID: 33532987
I already tried contacting IT... no dice. The security level can't be changed...

As far as AutoIT in Matlab goes I actually don't know how this works, but I already have a vbs script that's called in Matlab anyway that's able to press the "enable macros" button... the problem is that I need to open the workbook in Matlab in a way that brings up the prompt, that also stops executing once the prompt comes up so that I can then call the vbs script to press the button... winopen opens the workbook and the prompt does come up, but it doesn't stop executing until the prompt is already clicked out of so I'm not able to call the vbs file to click it...

0
 
LVL 6

Expert Comment

by:LeeeRussell
ID: 33533533
If I've understood your reply correctly, then something like an AutoIT script is capable of waiting until things have finished executing - that's one of the reasons I suggested it.
0
 

Author Comment

by:Jeff9687
ID: 33533689
Yeah, the problem is, though, that the vbs script is what gets through the prompt, it can't be run until winopen is finished executing, and winopen doesn't stop executing until the prompt is already passed so winopen will never stop executing... that's why my original idea was to modify winopen so that it just stops executing when the prompt comes up instead of waiting until the prompt is gotten through, but I can't because it works via a built-in mex function that I haven't been able to access...
0
 
LVL 6

Expert Comment

by:LeeeRussell
ID: 33534787
Yes, but if I've understood your problem correctly, you could get winopen to run the AutoIT script, which in turns opens the Excel file you need, and presses the buttons, then exits.  Would that solve your problem, or am I missing some intricacy of this problem?
0
 
LVL 15

Accepted Solution

by:
yuk99 earned 2000 total points
ID: 33573767
First of all MATLAB is not open source. It's true that most of the functions are implemented as m-files, but they cannot be redistributed. MEX files are compiled functions usually written in C/C++. Source codes for MEX files are not available (see my first sentence), so they cannot be modified without some kind of reverse engineering. Just forget about it.

For your problem you could add a line to your VBS script to open the Excel file first. Then use winopen from MATLAB to run this VBS script.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Introduction to Processes
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question