StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
 All Forums
 Lua Scripts
 General Action Scripts
 Open excel files with space character in path

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Pierre38 Posted - 09/25/2015 : 08:15:43
Hello
I'm new to this great tool, so apologies if this is a basic question. I looked in the forum and I did not find an answer to my question:
I'm trying to create a script to open a file with excel.
I found how to do it, but it does not work if the file has a space character in it.
The file I'm trying to open is :
C:\Users\Pierre\Documents\Personal documents\test.xlsx

I tried :
acRunProgram("C:\\Program Files (x86)\\Microsoft Office\\Office15\\excel.exe","C:\\Users\\Pierre\\Documents\\Personal documents\\test.xlsx",0, 1)
The script seems to fail because of the space character after "personal". It does not fail at the first space characters in "Program Files (x86"

Thanks in advance for your help
4   L A T E S T    R E P L I E S    (Newest First)
Rob Posted - 09/25/2015 : 09:19:57
Hmm, it's not escaped in my script and seems to work fine. Either way, I'm glad you're up and running!
Pierre38 Posted - 09/25/2015 : 09:12:35
Excellent thank you for the ultra quick reply!

For those who would re-use the solution with acShellExecute, a small typo in Rob's answer: the " needs to be escaped, so the correct syntax seems to be:

acShellExecute("open", "\"C:\\Users\\Rob.VOLSOL\\Documents\\Custom Office Templates\\test.xlsx\"", "", "", 1)
Rob Posted - 09/25/2015 : 08:57:17
Also, the reason the first parameter (path to Excel.exe) doesn't fail is because Windows knows that what's being passed into that parameter must only be the path to an executable (so it doesn't break on spaces)...and technically, it passes the full file path, verbatim, along to Excel, but it's standard for most programs to consider a space as the delimiter for parameters, so it's really Excel that needs the quotes around the file path.
Rob Posted - 09/25/2015 : 08:50:38
To answer your question, it's because you need to put the file path in quotes. Without quotes, Excel is passed 2 parameters (each space, when not inside of quotes, indicates a new parameter). Even though you have the path in quotes for your script, that's only so the Lua engine itself knows the beginning and end of the string, but it only passes what's inside the quotes along to Windows (so it has no quotes). You'll need to wrap it in escaped quotes (\") like this (file path on my machine):
acRunProgram("C:\\Program Files (x86)\\Microsoft Office\\Office15\\excel.exe",
             "\"C:\\Users\\Rob.VOLSOL\\Documents\\Custom Office Templates\\test.xlsx\"",0, 1)
However, I'd recommend using acShellExecute instead as it's less complicated, immune to Microsoft changing the location of excel.exe, and doesn't require escaped quotes; it's the equivalent of double-clicking the file in Windows:
acShellExecute("open", "C:\\Users\\Rob.VOLSOL\\Documents\\Custom Office Templates\\test.xlsx", "", "", 1)
Note that the verb parameter ("open") is essentially (not always, though) the text you see when you right-click a file, so it can also be used to perform actions like "print", "edit", etc.

StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000