3

I am trying to fix this legacy app that was created using Visual Studio 2003, using Microsoft Office Interops version 11, .NET 2.0. I am trying to fix it in Visual Studio Express 2010 to reference Interops version 14, .NET 4.0 -- as noted in my previous question on StackOverflow, the legacy app works fine in Windows 7 but after I close it, the Microsoft Office products are crashing when I try to use them.

However, when I fix the references in VS2010 (delete old v.11 Interops, add in new v.14 Interops) and then attempt to publish the application, I get errors like

'Microsoft.Office.Interop.Word.System does not contain a definition for IO'

It looks like VS2010 does not see my System namespace being used when the Word namespace is referenced? When I removed the

using Microsoft.Office.Interop.Word

namespace and then try to publish, the errors like the above disappear and I only get the expected errors related to the missing Word reference like

The type or namespace name '_Document' could not be found (are you missing a using directive or an assembly reference?)

I already included the System.dll in the reference so I'm not sure what's going on? Thanks for reading!

EDIT: I made "Embeded Interop Types" to be False for the Office Interops. That may have fixed some of the errors? HOWEVER: Visual Studio is still interpreting any System references to be "Microsoft.Office.Interop.Word.System" which is NOT what I want. This error seems to be the dominant one now:

The type name 'Windows' does not exist in the type 'Microsoft.Office.Interop.Word.System'
4

2 回答 2

6

这个问题发生在我身上,只有当我将 using 的东西放在命名空间定义之后,如下所示:

namespace Addin
{
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
..........................

正确的方法是:

using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Addin
{
....................

愿它帮助你!

于 2012-09-05T01:27:50.183 回答
0

要解决命名空间中的问题:

改变:

using Microsoft.Office.Interop.Word;

至:

using Document = Microsoft.Office.Interop.Word.Document;

对您可能从任何其他冲突命名空间使用的其他对象执行相同操作。

于 2013-06-06T02:34:12.003 回答