Process Start - Excel

DavyEFC

Well-known member
Joined
Dec 17, 2010
Messages
51
Programming Experience
5-10
I'm using the following code to open XML files in Excel, which works fine:
VB.NET:
    Dim startInfo As New ProcessStartInfo
    startInfo.FileName = "Excel.exe"
    startInfo.WorkingDirectory = c_OUCPath
    startInfo.Arguments = Me.lbxConfSent.SelectedItem
    Try
        Process.Start(startInfo)
    Catch ex As Exception
        frmMsgInput.ShowDialog("Error: " & ex.Message, , 3)
    End Try

...but i would like to modify so that files open in any existing instance of Excel rather than a new instance every time.
Not really an option to associate XML files with Excel permanently (so i could just pass the file name)
Any ideas?...
 
This works for me, code is using late binding for interop with COM automation, so Option Strict=Off for this code. Alternative is to reference Excel interop that require specific version installed.
        Try
            Dim app = Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
            app.Workbooks.Open("C:\test.xml") '(late binding)
        Catch ex As Runtime.InteropServices.COMException
            'Excel not open, or not installed
        End Try
 
Back
Top