VBA and Everything, escape quotation mark
VBA and Everything, escape quotation mark
Hi,
I want use VBA to launch everything with search term "ab cd" (quotations included).
VBA use "" to escape a single quotation(")
e.g. Msgbox """ab cd""" ---> "ab cd"
Everything command use """ to escape a single quotation(")
e.g. everything.exe -s """"ab cd"""" ---> "ab cd"
But when I combine both requirements into a single VBA Shell(), it didn't work.
What's the proper way to pass quotation mark from VBA to Everything search term?
Thanks.
I want use VBA to launch everything with search term "ab cd" (quotations included).
VBA use "" to escape a single quotation(")
e.g. Msgbox """ab cd""" ---> "ab cd"
Everything command use """ to escape a single quotation(")
e.g. everything.exe -s """"ab cd"""" ---> "ab cd"
But when I combine both requirements into a single VBA Shell(), it didn't work.
What's the proper way to pass quotation mark from VBA to Everything search term?
Thanks.
Re: VBA and Everything, escape quotation mark
Don't use VBA but I had to do a lot of trial and error with batch scripts. I have some places where I have to use 4 double quotes in a row. Did you try that?
Re: VBA and Everything, escape quotation mark
It has been ages since I even looked at VBA, but I vaguely remember running into these issues and solved them with using the ascii code of the double quotes.
Something like: char(34) & "ab cd" & char(34)
(Or was it chr(34)? )
Something like: char(34) & "ab cd" & char(34)
(Or was it chr(34)? )
Re: VBA and Everything, escape quotation mark
Thank you for your replies. I followed the directions but did not solve the problem regrettably.
My example vba code:
The content of Msgbox, when copy and paste as command, works as intended.
However it is the Shell script that cannot pass " quotation sign into Everything. (error: Unable to open file list: Files" is not a valid file list.)
If substituting " for chr(34):
Again, content of Msgbox is fine, Shell is throwing me error.
My example vba code:
Code: Select all
Dim sArg As String
sArg = """C:\Program Files\Everything\Everything.exe"""&" -s "&"""""""""Program Files"""""""""
Msgbox sArg
Shell(sArg,1)
However it is the Shell script that cannot pass " quotation sign into Everything. (error: Unable to open file list: Files" is not a valid file list.)
If substituting " for chr(34):
Code: Select all
sArg = """C:\Program Files\Everything\Everything.exe"""&" -s "&chr(34)&chr(34)&chr(34)&chr(34)&"Program Files"&chr(34)&chr(34)&chr(34)&chr(34)
Re: VBA and Everything, escape quotation mark
I don't have MS Office installed on my systems, so a wild guess ..
In Command Prompt, you need the following syntax:
In VBA, that should be soething like:
or
In Command Prompt, you need the following syntax:
"C:\path to \Everything.exe" -s """"Program Files""""
In VBA, that should be soething like:
Code: Select all
sArg = chr(34) & "C:\Program Files\Everything 1.5a\Everything64.exe" & chr(34) & " -s " & chr(34) & chr(34) & chr(34) & chr(34) & "Program Files" & chr(34) & chr(34) & chr(34) & chr(34)
Code: Select all
sArg = """C:\Program Files\Everything 1.5a\Everything64.exe"" -s """"""""Program Files"""""""""
Re: VBA and Everything, escape quotation mark
I found problem to be BASIC Shell randomly devouring quotaion mark when combined with space.
In following example, the second&third line devour the quotaion mark from the first due to having a space...
Anyway this isn't an Everything problem. Sorry for bothering you.
In following example, the second&third line devour the quotaion mark from the first due to having a space...
Code: Select all
Shell("msg %username% one" &chr(34)&chr(34)&chr(34)& "two" &chr(34)&chr(34)&chr(34),2) 'result: one"two"
Shell("msg %username% one" &chr(34)&chr(34)&chr(34)& "two " &chr(34)&chr(34)&chr(34),2) 'result: one"two
Shell("msg %username% one " &chr(34)&chr(34)&chr(34)& "two" &chr(34)&chr(34)&chr(34),2) 'result: one two
Re: VBA and Everything, escape quotation mark
I have some workarounds for the space quotation problem with Shell().
Workaround 1:
use Everything regex, replace space with \s in Shell()
Workaround 2:
enable Everything URL protocol, open hyperlink instead of Shell()
Workaround 1:
use Everything regex, replace space with \s in Shell()
Code: Select all
Shell("C:\Program Files\Everything\Everything.exe -s ""regex:Program\sFiles""",1)
enable Everything URL protocol, open hyperlink instead of Shell()
Code: Select all
Dim sURL As String
sURL="es:""""""Program Files"""""""
CreateUnoService("com.sun.star.system.SystemShellExecute").execute(sURL,"",0) 'for OpenOffice/LibreOffice Basic
Re: VBA and Everything, escape quotation mark
Thank you for sharing altoctave!
This will certainly help the next person with a similar issue.
This will certainly help the next person with a similar issue.