VBA and Everything, escape quotation mark

Plug-in and third party software discussion.
Post Reply
altoctave
Posts: 4
Joined: Thu Feb 06, 2025 9:32 pm

VBA and Everything, escape quotation mark

Post by altoctave »

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.
dedupeit
Posts: 55
Joined: Thu Jul 28, 2022 9:52 pm

Re: VBA and Everything, escape quotation mark

Post by dedupeit »

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?
NotNull
Posts: 5716
Joined: Wed May 24, 2017 9:22 pm

Re: VBA and Everything, escape quotation mark

Post by NotNull »

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)? )
NotNull
Posts: 5716
Joined: Wed May 24, 2017 9:22 pm

Re: VBA and Everything, escape quotation mark

Post by NotNull »

See also this thread
altoctave
Posts: 4
Joined: Thu Feb 06, 2025 9:32 pm

Re: VBA and Everything, escape quotation mark

Post by altoctave »

Thank you for your replies. I followed the directions but did not solve the problem regrettably.

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)
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):

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)
Again, content of Msgbox is fine, Shell is throwing me error.
NotNull
Posts: 5716
Joined: Wed May 24, 2017 9:22 pm

Re: VBA and Everything, escape quotation mark

Post by NotNull »

I don't have MS Office installed on my systems, so a wild guess ..

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)
or

Code: Select all

sArg = """C:\Program Files\Everything 1.5a\Everything64.exe""  -s """"""""Program Files"""""""""
altoctave
Posts: 4
Joined: Thu Feb 06, 2025 9:32 pm

Re: VBA and Everything, escape quotation mark

Post by altoctave »

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...

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
Anyway this isn't an Everything problem. Sorry for bothering you.
altoctave
Posts: 4
Joined: Thu Feb 06, 2025 9:32 pm

Re: VBA and Everything, escape quotation mark

Post by altoctave »

I have some workarounds for the space quotation problem with 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)
Workaround 2:
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
NotNull
Posts: 5716
Joined: Wed May 24, 2017 9:22 pm

Re: VBA and Everything, escape quotation mark

Post by NotNull »

Thank you for sharing altoctave!

This will certainly help the next person with a similar issue.
Post Reply