在 VB.net 中创建 Word 实例时出错
当我在 VS 2010 中运行此应用程序时出现错误(在 VS 2008 中工作正常)
Private SubGenerateInvoice()
Dim emptyObject As Object = System.Reflection.Missing.Value
Dim wordApp As New Word.Application
wordApp.Visible = True
Dim InvoiceDoc As New Word.Document
InvoiceDoc = wordApp.Documents.Add(InvoicePath, emptyObject, emptyObject, emptyObject)
Dim totalFields As Integer = 0
For Each mergeField As Word.Field In InvoiceDoc.Fields
错误发生在 For Each 行
“对象引用未设置为 对象的实例。”
我在这里遗漏了什么吗?
I am getting an error when I run this app in VS 2010 (it works fine in VS 2008)
Private Sub GenerateInvoice()
Dim emptyObject As Object = System.Reflection.Missing.Value
Dim wordApp As New Word.Application
wordApp.Visible = True
Dim InvoiceDoc As New Word.Document
InvoiceDoc = wordApp.Documents.Add(InvoicePath, emptyObject, emptyObject, emptyObject)
Dim totalFields As Integer = 0
For Each mergeField As Word.Field In InvoiceDoc.Fields
The error occurs at the For Each line
"Object reference not set to an
instance of an object."
Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许通过 VS2010 运行的实例中使用的
InvoicePath
无效,因此对Documents.Add
的调用失败?您是否在同一台计算机上运行 VS2010 和 VS2008?两个实例中的
InvoicePath
是否设置为完全相同的路径?Maybe the
InvoicePath
used in the instance run via VS2010 is invalid and so the call toDocuments.Add
fails?Are you running both VS2010 and VS2008 on the same machine? And is the
InvoicePath
set to the exact same path in both instances?尝试
Try