+ Reply to Thread
Results 1 to 6 of 6

Call external executable from excel 2007

  1. #1
    Registered User
    Join Date
    11-13-2009
    Location
    Hamilton ON
    MS-Off Ver
    Excel 2007
    Posts
    4

    Exclamation Call external executable from excel 2007

    Hi everybody, something crazy is happening to me. I wrote an external executable ("graph.exe") which is supposed to save a .xlsm file,
    close it, read some data from it, do some calculations, and print the results back into the same spreadsheet. When I double click "graph.exe" everything works. So I created a button in the spreadsheet I mentioned that should call "graph.exe" and therefore initiate the whole process. Here is the code:
    Please Login or Register  to view this content.
    When I click the button the .xlsm file is saved and closed, BUT than an error happens and "graph.exe" is not able to read any data from the sheet just closed! I tried to define an hyperlink to "graph.exe" as well, but I get the same problem! Does anyone know why? I was thinking it may have something to do with excel security settings or privacy options, but at this point I don't have a clue. Any suggestion would be greatly appreciated.
    Last edited by Manuel_; 11-20-2009 at 03:29 PM. Reason: forgot tags for code

  2. #2
    Registered User
    Join Date
    01-30-2009
    Location
    Estonia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19

    Re: Call external executable from excel 2007

    It's out of my league, sorry if completely irrelevant, but just a wild guess:

    Could you force your graph.exe to wait a little? Just to let Excel complete whatever it might be doing. Perhaps in a loop checking if file is accessible.

  3. #3
    Registered User
    Join Date
    11-13-2009
    Location
    Hamilton ON
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Call external executable from excel 2007

    I tried already, but it seems that it does not make any difference whatsoever. As soon as the pause comes to an end and the .xlsm is called I get the same error.

  4. #4
    Registered User
    Join Date
    01-30-2009
    Location
    Estonia
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19

    Re: Call external executable from excel 2007

    What does that error exactly say?

    How far exactly does graph.exe get? As i understand, it uses some kind of automation (relevant code bits might be clarifying - for smarter people), succeeds in contacting Excel, forcing save and close and fails when it tries to read data? But it sure finds that file? You do not specify path to workbook to graph.exe - is it hardcoded? Working directory does not change? Little debugging on graph.exe might give useful hints.

    And your workbook is not password protected or anything. All files are on a same filesystem and having no special permissions applied. And graph.exe works exactly as needed if called manually, problem arises only when you call it from the same file it must modify? And having open instance of Excel makes no difference in manual try?

    Yes, it does sound crazy.

    My second guess was that maybe that call to Shell() might keep workbook open, but little testing shows otherwise. Just to make sure: if you call that Shell() not from same workbook, but from Immediate window or other workbook - does it make any difference?

  5. #5
    Registered User
    Join Date
    11-13-2009
    Location
    Hamilton ON
    MS-Off Ver
    Excel 2007
    Posts
    4

    Thumbs up Re: Call external executable from excel 2007

    Thanks for the hint! Actually it did not find the .xlsm file.
    When I call graph.exe manually it looks for the .xlsm file in the current directory, BUT when I call graph.exe from inside Excel it looks for my .xlsm file in the Excel default file location! To solve this I added a macro in my .xlsm:
    Please Login or Register  to view this content.
    which is run as soon as my .xlsm is opened and changes Excel default dir with my current working dir where I stored my .xlsm. I noticed a bug though. In order to make the change effective I need to restart Excel, otherwise the default dir is not updated. Thanks again.

  6. #6
    Registered User
    Join Date
    11-13-2009
    Location
    Hamilton ON
    MS-Off Ver
    Excel 2007
    Posts
    4

    Thumbs up Re: Call external executable from excel 2007

    Even better:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1