在 VB.net 中创建 Word 实例时出错

发布于 2024-10-02 07:48:22 字数 547 浏览 0 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦魇绽荼蘼 2024-10-09 07:48:22

也许通过 VS2010 运行的实例中使用的 InvoicePath 无效,因此对 Documents.Add 的调用失败?

您是否在同一台计算机上运行 VS2010 和 VS2008?两个实例中的 InvoicePath 是否设置为完全相同的路径?

Maybe the InvoicePath used in the instance run via VS2010 is invalid and so the call to Documents.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?

淡淡绿茶香 2024-10-09 07:48:22

尝试

 Dim InvoiceDoc As Word.Document
 wordApp.Documents.Add(InvoicePath, emptyObject, emptyObject, emptyObject)
 InvoiceDoc=wordApp.ActiveDocument

Try

 Dim InvoiceDoc As Word.Document
 wordApp.Documents.Add(InvoicePath, emptyObject, emptyObject, emptyObject)
 InvoiceDoc=wordApp.ActiveDocument
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文