无法识别Microsoft.Office.Interop.Word命名空间的别名 [英] Alias for Microsoft.Office.Interop.Word namespace not recogized

查看:173
本文介绍了无法识别Microsoft.Office.Interop.Word命名空间的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Form1.vb中的代码:

Here is my code in Form1.vb:

Imports Word = Microsoft.Office.Interop.Word

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click

    Dim oWord As Word.Application
    Dim oWord1 As Microsoft.Office.Interop.Word.Application
    Dim oWord2 as Application

我正在使用VStudio2012和Office 2010,并遵循 https://support.microsoft.com上的示例/kb/316383

I'm using VStudio2012 and Office 2010 and following the sample from https://support.microsoft.com/kb/316383

oWord 的声明被智能感知标记为未定义'Word.Application'类型,
oWord1 oWord2 被接受. Intellisense提供了几个错误纠正选项-我已经尝试了其中的两个(oWord1和oWord2)-其他选项似乎并不适用.

The declaration of oWord is flagged by intellisense as "Type 'Word.Application' is not defined,
while oWord1 and oWord2 are accepted. Intellisense provides several error correction options - two of which I've tried (oWord1 and oWord2) - the other options don't seem to apply.

简而言之,我对为什么在Imports语句上使用名称空间别名Word不能满足KB文章中所述的 Dim oWord As Word.Application 感到困惑.是否有一些主旋钮"可用于打开项目属性对话框或其他内容?

In short, I am confused about why the use of the namespace alias Word on the Imports statement does not satisfy the syntax Dim oWord As Word.Application as described in the KB article. Is there some "master knob" to turn in the project properties dialog or something?

推荐答案

您将需要添加引用以导入此命名空间的DLL.在Visual Studio 2012中,在您的解决方案资源管理器中,右键单击项目名称>单击添加引用">选择程序集">扩展名">"Microsoft.Office.Interop.Word".互操作库可能有多个版本(Office 2003、2007、2010等),请选择适当的版本.

You will need to add a reference to import the DLL for this namespace. In Visual Studio 2012, in your solution explorer` right click on the project name > click "Add Reference" > Choose "Assemblies" > "Extensions" > "Microsoft.Office.Interop.Word". There may be multiple version of the Interop Libraries (Office 2003, 2007, 2010, etc), choose the appropriate one.

我相信这些组件最初是从DVD安装Microsoft Office时安装的.因此,我相信您需要安装Word.

I believe these assemblies are originally installed when you do your installation of Microsoft Office from the DVD. So you will need to have Word installed I believe.

使用Intellisense,此功能对我有用:

this works for me, with Intellisense:

Imports Word = Microsoft.Office.Interop.Word
Module Module1
    Sub Main()
        Dim oWord As Word.Application
    End Sub
End Module

这篇关于无法识别Microsoft.Office.Interop.Word命名空间的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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