You can't use API calls in VBS because they
require speficic data types and access to memory
locations. But you can do the equivalent in many
cases. In this case you can just do what
FindExecutable does:
- Read the Registry key default value in HKCR\.xlsx
- That should be a string like "Xlsx File"
- Read the Registry key under HKCR\Xlsx File
There should be a series of keys like so:
HKCR\Xlsx File\shell\open\command\
The default value there is the path to the
executable, assuming the file extension is
registered.
There are a couple of catches: Sometimes
the path will contain something like %system root%,
which needs to be translated. Also, WScript.Shell,
the official way to access the Registry, is not
very dependable. More dependable is to use WMI,
but that's also very messy. See if the simple way
works for what you need:
Dim SH, s, s2
Set SH = CreateObject("WScript.Shell")
s = SH.RegRead("HKCR\.txt\")
s2 = SH.RegRead("HKCR\" & s & "\shell\open\command\")
s2 = SH.ExpandEnvironmentStrings(s2)
MsgBox s2
Set SH = Nothing
That should display the path to Notepad. Notice
that it also probably has "%1" at the end. It may
also have other parameters. So the last step in
returning the executable path is to find the last \
and then strip off at the next space:
Pt1 = Instrrev(s2, "\")
Pt2 = InStr(Pt1, s2, " ")
If Pt2 > 0 Then s2 = Left(s2, (Pt2 - 1))
MsgBox s2