Word 2010自动化VB.NET 2010 [英] Word 2010 Automatisierung mit VB.NET 2010

查看:109
本文介绍了Word 2010自动化VB.NET 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ich versuche seger geraumer Zeit eine VB.NEt Anwendung mit Word 2007 Automatisierung von VB.NET 2008 auf VB.NET 2010和Word 2010 umzustellen.
问题和解决方案问题:

常见问题解答"Microsoft.Office.Interop.Word.DocumentClass"常见问题解答,请参见"WindowsApplication1.word.Document". Instanzen von Typen,死于COM-Komponenten代表,Könnennicht在Andere Typen umgewandelt werden,死于Keine COM-Komponenten代表. Eine Umwandlung在Schnittstellen出版的《 JedochMöglich》中,在Zugrunde liegende COM-Komponente QueryInterface-Aufrufefürdie IID der Schnittstelleunterstützt中进行了搜索.

坎恩·米尔·杰曼德·韦特赫尔芬?

马蒂亚斯

翻译:

我尝试将VB.NEt与VB.NET 2008的Word 2007自动化一起使用以切换到VB.NET 2010和Word2010.我的所有示例均在较旧的版本中发现并产生相同的问题:

类型Microsoft.Office.Interop.Word.DocumentClass的COM对象不能强制转换为类类型" WindowsApplication1.word.Document.代表COM组件的类型的实例不能转换为不代表COM组件的其他类型.前提是支持该接口的IID的基础COM组件QueryInterface调用,就可以使用转换接口.

有人可以帮我吗?

Ich versuche seit geraumer Zeit eine VB.NEt Anwendung mit Word 2007 Automatisierung von VB.NET 2008 auf VB.NET 2010 und Word 2010 umzustellen.
Alle von mir gefundenen Beispiele stammen aus älteren Versionen und erzeugen das gleiche Problem:

Das COM-Objekt des Typs "Microsoft.Office.Interop.Word.DocumentClass" kann nicht in den Klassentyp "WindowsApplication1.word.Document" umgewandelt werden. Instanzen von Typen, die COM-Komponenten repräsentieren, können nicht in andere Typen umgewandelt werden, die keine COM-Komponenten repräsentieren. Eine Umwandlung in Schnittstellen ist jedoch möglich, sofern die zugrunde liegende COM-Komponente QueryInterface-Aufrufe für die IID der Schnittstelle unterstützt.

Kann mir jemand weiterhelfen?

Matthias

TRANSLATION:

I have tried for some time a VB.NEt use with Word 2007 automation from VB.NET 2008 to switch to VB.NET 2010 and Word 2010. All of my examples are found in older versions and produce the same problem:

The COM object of type Microsoft.Office.Interop.Word.DocumentClass "can not be cast to the class type" WindowsApplication1.word.Document. Instances of types that represent COM components can not be converted into other types that do not represent COM components. A conversion interfaces is possible, provided that the underlying COM component QueryInterface calls for the IID of the interface supports.

Can anyone help me?

推荐答案

您没有提供正在使用的代码,因此请尝试以下操作:

You didn''t provide the code you''re using, so try this:

DocumentClass m_Doc = (DocumentClass)m_App.Documents.Open(FileName: m_strTemplate);



或在VB.NET中:



Or in VB.NET:

Dim m_doc as documentclass = DirectCast(m_App.Documents.Open(FileName: m_strTemplate))



编辑===========

纠正了Dave Kreskowiak的无效VB代码(检查版本以了解我的意思).



EDIT ===========

Corrected Dave Kreskowiak''s invalid VB code (check versions to see what I mean).


感谢您的帮助,
(我使用VB.NET 2010和Office 2010)

刚才我通过以下方式自己解决了问题:

1.我从PIA Office 2010的Microsoft.Office.Interop.Word.Document中引用了

2.然后,我在模块中导入了Microsoft.Office.Interop.Word

3.我将CType-Expression中的Object从Word.Document更改为
Microsoft.Office.Interop.Word.Document(请参见粗体字)

4.现在可以使用了

导入Microsoft.Office.Interop.Word
作为Microsoft.Office.Interop.Word.Document的公共文档

公共Sub Druck()
...

''打开文档
试试
doc = CType(GetObject("abc.doc"), Microsoft.Office.Interop.Word.Document )
赶上
MessageBox.Show("...","...",MessageBoxButtons.OK,MessageBoxIcon.Error)
退出子
结束尝试

doc.Application.Visible = False
doc.ActiveWindow.Activate()
使用doc.Application
''填写文件
...
结束Sub
Thank you for your help,
(I use VB.NET 2010 an Office 2010)

Just now I solved the problem myself in the following way:

1. I referenced from Microsoft.Office.Interop.Word.Document from PIA Office 2010

2. then I imported Microsoft.Office.Interop.Word in the Module

3. I changed the Object at the CType - Expression from Word.Document to
Microsoft.Office.Interop.Word.Document (see the bold text)

4. now it works

Imports Microsoft.Office.Interop.Word
Public doc As Microsoft.Office.Interop.Word.Document

Public Sub Druck()
...

''open Document
Try
doc = CType(GetObject("abc.doc"), Microsoft.Office.Interop.Word.Document)
Catch
MessageBox.Show("... ", "...", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try

doc.Application.Visible = False
doc.ActiveWindow.Activate()
With doc.Application
''fill the document
...
End Sub


这篇关于Word 2010自动化VB.NET 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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