I needed the GetCommandLine function for VBA several times, but I cannot find any working code of the Win32 api function on net. You cannot simply use App.ExeName property or Command function, because these two VBA methods does not work if you create VBA COM DLL project.
You also cannot directly use GetCommandLine in VBA declaration, something like
Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As stringThis simple code do not work, because GetCommandLine returns a pointer to string, which VBA cannot handle directly. You have to use another Win32 functions, which works with pointers. I have choosen lstrlenA to get a length of the command line string and lstrcpynA to copy command line to a VBA buffer.
for 'GetCommandLine Win32 function for VBA/VB' article
Copyright and use this code
The source code on this page and other samples at https://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
2. Link this sample from you page.
<A Href="https://www.motobit.com/tips/detpg_vba-getcommandline/" Title="Code to call GetCommandLine function from VBA - Excel, Word and other software with Visual Basic" >GetCommandLine Win32 function for VBA/VB</A>
© 1996 - 2014 Antonin Foller, Motobit Software | About, Contacts | (Find us on Google+)