Access VBA: How To Call A Windows Form Application with Arguments

To call a Windows Form application (*.exe) with arguments in VBA, you use the Shell() function.

Shell "C:\Dev\SampleWinFormWithArgs.exe arg1", vbNormalFocus

 

Inside the Windows Form application, you get the command line arguments using Environment.GetCommandLineArgs().

string[] args = Environment.GetCommandLineArgs();
// you can call GetCommandLineArgs() anytime, anywhere
foreach(string arg in args)
{
    // do stuff
    // note that the first argument string is the application pathname
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s