问题描述
我想让一个Excel工作簿在某些进程结束时走到前台。
I want to make an Excel workbook come to the foreground towards the end of some processes.
目前,使用下面的代码,它是一个命中和错过。通常情况下,工作簿会留在后台。
At the moment, with the code below, it is a hit and miss. Often times the workbook is left in the background.
声明自动函数SetForegroundWindow Lib" USER32.DLL" ; (ByVal hWnd As IntPtr)As Boolean
Declare Auto Function SetForegroundWindow Lib "USER32.DLL" (ByVal hWnd As IntPtr) As Boolean
Dim wb As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim wb As Microsoft.Office.Interop.Excel.Workbook = Nothing
wb = GetObject(path +文件名)
wb = GetObject(path + filename)
wb.Application.Visible = True
wb.Application.Visible = True
wb.Windows(1).Visible = True
wb.Windows(1).Visible = True
SetForegroundWindow(wb.Application.Hwnd)
SetForegroundWindow(wb.Application.Hwnd)
除了上面的最后一行,我还尝试了不同类型的循环,喜欢:
Instead of the last line above, I have also tried different kinds of loops, like:
         请按
              SetForegroundWindow(wb.Application.Hwnd)
$
         循环时不是SetForegroundWindow(wb.Application.Hwnd)
Do
SetForegroundWindow(wb.Application.Hwnd)
Loop While Not SetForegroundWindow(wb.Application.Hwnd)
但是代码经常卡在循环中
but often the code gets stuck in the loop
我已在帮助页面中读到了SetForegroundWindow不起作用的条件,但它们似乎不适用于此。
I have read in the Help pages the conditions where the SetForegroundWindow does not work, but they do not seem to apply here.
如何让工作簿到达前台?
How do I make the workbook come to the foreground?
推荐答案
这篇关于SetForegroundWindow并不总是有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!