在VB.net创建Word实例时出错 [英] Error when creating an instance of Word in VB.net

查看:178
本文介绍了在VB.net创建Word实例时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个错误,当我在VS 2010中运行这个程序(正常工作在VS 2008中)

I am getting an error when I run this app in VS 2010 (it works fine in VS 2008)

私人小组GenerateInvoice()

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."

我失去了一些东西呢?

推荐答案

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

Maybe the InvoicePath used in the instance run via VS2010 is invalid and so the call to Documents.Add fails?

您在同一台机器上同时运行VS2010和VS2008?而在 InvoicePath 设置完全相同的路径在这两种情况?

Are you running both VS2010 and VS2008 on the same machine? And is the InvoicePath set to the exact same path in both instances?

这篇关于在VB.net创建Word实例时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆