我有一个VB.net 测试的应用程序,点击链接,打开了微软的Word应用程序的窗口,并显示文件。我怎么找到这个词应用的窗口,使我可以抓住一些文字吗?

有帮助吗?

解决方案

你可以用这个词COM对象开的工作文件,然后你操纵。确保添加一个参考为Microsoft Word第一次。

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Word

Public Class Form1

Inherits System.Windows.Forms.Form

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

Dim strFileName As String
Dim wordapp As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document

Try
    doc = wordapp.Documents.Open("c:\testdoc.doc")
    doc.Activate()

Catch ex As COMException

    MessageBox.Show("Error accessing Word document.")

End Try

End Sub

End Class

Doc对象是处理实例的话,你已创建并且可以使用所有正常方案(保存、印刷等等)。你可以做同样的wordapp.一个技巧是使用宏编字记录你想要做什么.然后你可以查看这在宏编辑器。这给你一个很好的起点你VB代码。

此外,可以肯定处置一词COM对象的结束。

其他提示

我已经做了类似的东西一章对话,这是我贴在我的博客。基本上我使用的任间谍++或Winspector找出窗口类名称,并使Win32呼吁做的东西用窗口。我已经把源在我的博客: http://harriyott.com/2006/07/sourcesafe-cant-leave-well-alone.aspx

你是想 激活 这个词的应用程序?如果你想完全控制,你需要自动化的单词从你的vb.net 应用程序。在这里检查一些样品: 1, 2

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top