为什么 Word 不“出现在前面”?当我们激活它时?
我们的 winforms 应用程序与 MS Word 交互,当生成文档时我们运行此代码,并且我们希望在我们的应用程序前面的 Word 中显示它:
[setup w as a Word interop object]
w.Visible = True
w.Activate()
当推出到运行 Office 2007 的 XP 计算机时,它的工作原理如下故意的。
在运行 Office 2010 的 Win7 计算机上,文档会加载到我们的应用程序后面并在任务栏上闪烁。
有什么想法吗?
Our winforms application interacts with MS Word and we run this code when a document is generated and we want to show it in Word in front of our application:
[setup w as a Word interop object]
w.Visible = True
w.Activate()
When rolled out to XP machines running Office 2007 this works as intended.
On Win7 machines running Office 2010 the document loads behind our application and flashes on the taskbar.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我最近偶然发现了类似的问题。我的.NET程序称为COM应用程序,但在Win7上它有时既不会显示在任务栏中,也不会显示在桌面上。我无法真正找出原因,但我编写了以下函数来解决该问题:
I stumbled upon a similar problem recently. My .NET program called a COM application, but on Win7 it would sometimes neither show up in taskbar nor on the desktop at all. I wasn't really able to track down the cause of this, but I wrote the following function to work around the issue:
将应用程序从带有 Word 2002&3 的 XP 转换为带有 Word 2010 的 Win 7 时遇到同样的问题。发现您打开的第一个文档出现以下情况,之后任何新文档都会在任务栏中闪烁。
打开Word文档后:
策略是转到显示文档的窗口。最小化和最大化会将文档的窗口置于最前面。
您可以对应用程序对象执行相同的操作(如此处建议的 http: //www.access-programmers.co.uk/forums/showthread.php?t=173871 注意:如果窗口一开始就最大化,则最大化而不最小化没有帮助),但是如果您有很多Word打开文档,您会认为您已经赢得了 Windows 中的纸牌游戏...
Had the same issue when converting an application from XP with Word 2002&3 to Win 7 with Word 2010. Found the following works for the first document you open, after that any new documents appear in the task bar blinking.
After opening the Word Document:
The strategy is to go after the Window in which the document is displayed. Minimizing and maximizing will bring the document's window to the front.
You can do the same with the application object (as suggested here http://www.access-programmers.co.uk/forums/showthread.php?t=173871 note: maximize without minimize doesn't help if the window is maximized to begin with), but if you have many Word documents open you'll think you've won a game of solitare in Windows...
我不是专家,但我遇到了同样的问题并在这里找到了方法。我无法获得任何其他解决方案的工作,但我刚刚在这里找到了我的问题的答案...
http://david.gardiner.net.au/2010/05/bad-old-days-of-vba-and-opening- word.html
我刚刚在我的代码中添加了一行,如下所示(粗斜体行),Word 文档在 Win 7 上的 Excel 前面打开运行 Office 2010 的计算机:
Dim wordApplication
Set wordApplication = CreateObject("Word.Application")
Application.ActivateMicrosoftApp xlMicrosoftWord
有关其工作原理的更多信息,请访问上面的链接。
I'm no expert but I hit this same problem and found my way here. I couldn't get any of the other solutions to work but I just found an answer to my problem here...
http://david.gardiner.net.au/2010/05/bad-old-days-of-vba-and-opening-word.html
I just added one line as follows (the line in bold italics) to my code and Word docs opened up in front of Excel on Win 7 machines running Office 2010:
Dim wordApplication
Set wordApplication = CreateObject("Word.Application")
Application.ActivateMicrosoftApp xlMicrosoftWord
More information on why this works at the link above.
我发现的最简单的方法是
The simplest method I found out is
w.Visible = True
w.Activate()
对我来说很好用!
看看其他原因。
例如
文档出现在前面。
w.Visible = True
w.Activate()
Works for me fine!!!
See the other reasons.
for example
Document comes to front.