vba 新建进程且窗口置顶

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vba 新建进程且窗口置顶相关的知识,希望对你有一定的参考价值。

 


Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Sub Window_Top() ‘调用API函数,实现窗口最前
Dim WINWND As Long
WINWND = FindWindow(vbNullString, Application.Caption)
SetWindowPos WINWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

 

Sub CreateApp()

 

Dim wb As Workbook
‘ Set wb = Workbooks.Open("D:/B.xls")

Set app = CreateObject("Excel.Application")
app.Visible = True


app.Workbooks.Open ("C:\vba-test\123.xlsx")


WINWND = FindWindow(vbNullString, app.Caption)
SetWindowPos WINWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

 

 

End Sub

以上是关于vba 新建进程且窗口置顶的主要内容,如果未能解决你的问题,请参考以下文章

在有序数据表中实现多记录上移下移置顶置底算法思路

怎么使通过进程打开的win32程序窗口始终置顶

CSS怎么设分别置大DIV里面的3个并排小DIV靠左 居中 靠右!

WPF实现只打开一个窗口,并且重复打开时已经打开的窗口置顶

vb取消窗口置顶

MFC 如何使窗口 置顶