Alias for Microsoft.Office.Interop.Word namespace not recogized

拟墨画扇 提交于 2020-01-03 16:59:08

问题


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

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

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.

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?


回答1:


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.

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.

Edit: 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



回答2:


Instead of 'Imports Word = Microsoft.Office.Interop.Word' I used 'Imports Microsoft.Office.Interop' and it worked fine



来源:https://stackoverflow.com/questions/20911217/alias-for-microsoft-office-interop-word-namespace-not-recogized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!