【发布时间】:2014-08-17 20:45:18
【问题描述】:
我正在尝试从 Access 打开一个 Excel 文件,它确实可以工作,但是 Excel 窗口会在后台弹出(在 Access 窗口后面),这对用户不是很友好。这是我使用的代码:
Private Function OpenExcelAttachment()
Dim MyXL As Object
Set MyXL = CreateObject("Excel.Application")
With MyXL
Dim FullPath As String, Name As String
Name = "\ExcelFile.xlsx"
FullPath = CurrentProject.Path & Name
.Workbooks.Open FullPath
.Visible = True
End With
我怎样才能让 Excel 窗口出现在前台(在所有打开的窗口之上)?
谢谢!
【问题讨论】:
-
应该是这样,因此您的代码没有问题。程序只有很少的时间将自己设置为前台窗口,是不是加载文件的时间很长?尝试先设置可见然后加载文件。
The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true: -
The process is the foreground process. The process was started by the foreground process. The process received the last input event. There is no foreground process. The foreground process is being debugged. The foreground is not locked (see LockSetForegroundWindow). The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo). Windows 2000/XP: No menus are active. -
感谢您的回复!文件很小,所以根本不需要很长时间。当我设置可见时玩弄也没有帮助。有趣的是,我发现如果我在调用 Excel 之前打开 VBA,它确实会显示在前台!但是,如果我退出 Access,再次打开它并调用 Excel(潜在用户会这样做),它会在后台显示...
-
从 MS 编程语言工具文件夹或 Windows SDK 工具文件夹中尝试 Spy++。通过记录所有消息查看发生了什么。