Pass information from VBA to VB.NET

时间:2017-07-12 08:13:17

标签: vb.net vba

I'm trying to pass a string from a VBA application (running through MicroStation - CAD Draftiong Tool) to a VB.NET program but having some difficulty. I have found a couple of threads on here to do similar but mine doesn't seem to want to work.

The VBA part of the issue is here. This code came from another Stackoverflow thread asking a similar question to what i am.

    Dim strProgramName As String
    Dim strArgument As String

    strProgramName = HPDIR & "Utilities\HP_CheckForUpdates.exe"
    strArgument = "/ver=" & vVersion(0)

    Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)

My issue is how can i get my VB.NET program to read the argument above? On another thread i found "Environemnt.GetCommandLineArgs", but mine always returns "System.String[]"

Essentially all i am trying to do is grab the string from VBA and display it in VB.NET. I am happy to hear of other / better ways to do it rather than arguments.

1 个答案:

答案 0 :(得分:0)

以下是如何将命令行参数从一个vb程序发送到另一个vb程序

发件人模块:

Module Module_Sender

    Sub Main()

        Dim strCommand As String
        strCommand = "CommandReciever.exe" + Space(1) + " ali"

        Console.WriteLine("Sending shell command ... ")

        Interaction.Shell(strCommand, AppWinStyle.NormalFocus)

    End Sub

End Module

接收器模块:

Module Module_Reciever

    Sub Main()
        Dim args() As String = System.Environment.GetCommandLineArgs()

        If (args.Length > 0) Then
            'display param And exit
            Console.WriteLine("Program param = " + args(1))
            Console.WriteLine("press enter key to exit ...")
            Console.Read()
            Return 'System.Environment.Exit(1);
        Else
            Console.WriteLine("Hey, Program id param expected ...")
        End If


    End Sub

End Module