Process.Start and WinWord

DiverDan

Well-known member
Joined
Jan 16, 2003
Messages
645
Location
Sacramento, CA
User Rank
*Experts*
Im getting an invalid path error when starting MS Word from Process.Start with a OpenFileDialog filename. Other applications like NotePad and Excel work fine...the problem is only with Word. Does anyone have an idea to solve this problem.

Heres the code Im using:

Code:
OpenFileDialog1.Title = "Open Contract Files"
OpenFileDialog1.InitialDirectory = Application.StartupPath & "\Contracts"
OpenFileDialog1.Filter = "Contracts (*.doc)|*.doc|Worksheets (*.xls)|*.xls|All Files (*.*)|*.*"
OpenFileDialog1.DefaultExt = "doc"
OpenFileDialog1.AddExtension = True
If OpenFileDialog1.ShowDialog() = DialogResult.Cancel Then Exit Sub
If OpenFileDialog1.FileName.IndexOf(".txt") >= 0 Then
   System.Diagnostics.Process.Start("notepad.exe", OpenFileDialog1.FileName)
ElseIf OpenFileDialog1.FileName.IndexOf(".doc") >= 0 Then
   System.Diagnostics.Process.Start("WINWORD.EXE", OpenFileDialog1.FileName)
ElseIf OpenFileDialog1.FileName.IndexOf(".xls") >= 0 Then
   System.Diagnostics.Process.Start("EXCEL.EXE", OpenFileDialog1.FileName)
End If

Thanks
 
you know that you can just use the filename to open the process dont you? ( for all those processes ) , eg:
Code:
With OpenFileDialog1
    .Title = "Open Contract Files"
    .InitialDirectory = Application.StartupPath & "\Contracts"
    .Filter = "Contracts (*.doc)|*.doc|Worksheets (*.xls)|*.xls|All Files (*.*)|*.*"
    .DefaultExt = "doc"
    .AddExtension = True
End With

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    System.Diagnostics.Process.Start(OpenFileDialog1.FileName) /// open the file in its default app ( eg: word / IE / Notepad etc... )
End If
 
Back
Top