我正在开发一个需要启动 Microsoft Word,然后在用户关闭 Word 时恢复的应用程序。下面的代码应该可以工作,但不能。我得到一个“对象未设置为对象的实例”
1 Dim pInfo As New ProcessStartInfo
2 Dim P As New Process
3 pInfo.FileName = "C:\test\LLR.doc"
4 P = Process.Start(pInfo)
5 ''# Here is where it goes bad
6 P.WaitForInputIdle()
7 P.WaitForExit()
我p
进入手表窗口,它system.diagnostics.process
在第 2 行之后的手表中显示 aa,但在第 4 行之后它返回到 NOTHING。进程启动,但我无法再使用第 6 行和第 7 行对其进行监控。这是 Visual Studio 2010 的“限制”还是我犯了操作错误?MS 帮助未显示 2010 版本中可用的进程(它位于 Visual Studio 2005 和 Visual Studio 2008 中)。
--根据反馈进行编辑-最终解决方案
Private Function StartWord(ByVal NewFileName As String) As Boolean
MessageBox.Show("When you have finished editing the report, save and close word to complete operation")
Dim wapp As Application
wapp = New Microsoft.Office.Interop.Word.Application
wapp.Documents.Open(NewFileName)
wapp.Visible = True
wapp.WindowState = WdWindowState.wdWindowStateMaximize
wapp.Caption = "Large Loss Report"
Try
While wapp.Documents.Count > 0
System.Windows.Forms.Application.DoEvents()
End While
wapp.Quit()
Catch ex As Exception
End Try
Return True
End Function