我正在尝试打开一个文件,但Office应用程序在VB.NET文档打开期间挂起。
我有这段代码:
Dim oProp As Object
Dim strPropValue As String
Dim lngRetVal As Integer
Dim strmsg As String
Dim lngretcode As Integer
Dim strPropertyName As String
Dim oWordDoc As Word.Document
Dim ObjOfficeAPP As Object
ObjOfficeAPP = New Word.Application()
GetWORDKEYS = cstFAILURE
ObjOfficeAPP.DisplayAlerts = WdAlertLevel.wdAlertsAll
ObjOfficeAPP.Application.Visible = True
oWordDoc = ObjOfficeAPP.Documents.Open(FileName:=strpFileName, Visible:=False)
我遇到问题:
oWordDoc = ObjOfficeAPP.Documents.Open(FileName:=strpFileName, Visible:=False)
调试器挂起在Documents.Open()调用上,只是等待 - 不会触发任何类型的异常或错误。我们查看了事件日志,但只找到了以下内容。
我的问题是,如何设置打开此文档而不是阻止Documents.Open()
来电?
答案 0 :(得分:0)
以下几点可以提供帮助:
请勿使用Application
属性设置Visible
属性:
ObjOfficeAPP.Visible = True
在打开文档之前,请不要设置DisplayAlerts
属性。
System.Reflection.Missing.Value
表示缺少参数。 您可能会发现How to automate Word from Visual Basic .NET to create a new document文章有用,它解释了自动化Word所需的步骤并提供了示例代码:
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add