Solved

modify built-in matlab mex file

Posted on 2010-08-25
10
772 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
  • 5
  • 4
10 Comments
 
LVL 6

Expert Comment

by:LeeeRussell
Comment Utility
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
Comment Utility
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
Comment Utility
When you open the Excel spreadsheet directly (not from Matlab) do you have to click on "Enable macros"?
0
 

Author Comment

by:Jeff9687
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Jeff9687
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now