Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

shell function call exe

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Shell function to call .exe

Shell function to call .exe

ResolvedVersion 2007

Vlad has attended:
Excel VBA Intro Intermediate course

Shell function to call .exe

Hello,

I have recently been using the following code to call a .exe in the same location as my workbook.

Shell (ActiveWorkbook.Path & "\myfile.exe")

This works fine when I run it on the C: drive.

However, if I move the files to a network folder (the workbook and .exe are in the same folder), VBA returns no errors but the .exe does not run correctly (the .exe is a fortran code with text outputs. It appears to run but produces no output files).

I can run the .exe by clicking on it no matter where it is and it produces correct outputs. It's only when I try to call it with Shell that it doesn't work.

VBA also appears to have no permission issues, as it happily creates folders and copies files around on the network drive or any drive for that matter.

Even more bizarre, when I call the .exe from VBA in a network folder, the .exe appears to run, creates no outputs in the folder it should, but in fact creates phantom (blank) outputs in the "My Documents" folder.

I hope I explained that well enough. Please let me know if there is a way around this, because ideally I would like users to just copy this package (workbook and .exe), share it across network drives and for it to work anywhere.

Thanks,

Vlad

RE: Shell function to call .exe

Hi Vlad

Thanks for getting in touch.

Across a network the Shell command's path parameter is treated slightly differently. Does the path have spaces in? Locally, the system can resolve this. Over a network, it often runs in to difficulty. Using double quotes (") around the path can help, but you might have to concatenate it if you are using a variable to stand in for the path.

Is it possible to try out a couple of tests? What happens if you specify a manual path, both locally and over the network?

I hope this helps.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Shell function to call .exe

Hi Gary,

Thanks for the quick reply,

There are no spaces in the file path.

The result is the same if I hard-code the entire path inside "" or if I concatenate with the ActiveWorkbook.Path variable. It still misbehaves as described.

Regards,
Vlad

RE: Shell function to call .exe

Hi Vlad

Thanks for the reply.

I'm going to put my head together with the other VBA trainers on this one, so I will get back to you early next week when we've had a chance to think about it.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Shell function to call .exe

Hi Gary,

Thanks for looking into it.

Just an extra bit of information for you. I got Shell to output the Task ID number, and it outputs a (non-zero) number even when the .exe runs incorrectly. So Shell seems to think it's run fine when it hasn't.

Regards,

Vlad

RE: Shell function to call .exe

Hi Vlad

Thanks for your reply.

We've had a think about it and searched around and can't seem to find any other reason why it shouldn't work.

Unfortunately we're unable to reproduce the issue either, so that makes it harder to diagnose.

Your process outputs text files; can you run the process locally and then move the files as part of the batch file? Will an internal network admin be able to help diagnose where it thinks files are being created and whether there are valid permissions for it to do so?

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Shell function to call .exe

Hi Gary,

Thank's for looking into this. Unfortunately, I have been unable to ascertain from my network admins exctly what permissions issues may be causing this problem.

Although I could make the routine move the files to a different folder, it may be a simpler solution in this case just to instruct users to run the routine locally.

I will mark the question as closed, since it seems to be a very specific glitch in the interaction between Shell and my company network and I unfortunately do not have more time to try to work it out.

Thanks again,

Vlad

Excel tip:

Quickly copy a formula across sheets

Suppose you have a formula in cell Sheet1!B2, say =A1*5%, that you wish to copy to cell B2 on Sheet2, Sheet3 and Sheet4. Instead of using copy and paste, try this: (1) Select Sheet1!B2. (2) Group Sheet1 with the worksheets Sheet2, Sheet3 and Sheet4 by holding down Ctrl and clicking on the tabs of the sheets to group them. (3) Press the F2 key, then immediately press Enter to copy the formula in Sheet1!B2 across the grouped sheets.

Remember to ungroup the sheets afterwards! Right-click on any tab and choose Ungroup Sheets to do that.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.