I am trying to create a spreadsheet to track my online poker play. Here is more detail on what I am trying to do. That is why I think something is wrong with SetWindowPos and the type of window I am trying to keep on top. Below are the only lines that differ between the two:
Closeprocess api vba windows#
The second sub posted is identical except that it closes windows and it always works. When I watched it execute line by line, I watched the varables and it correctly finds the window and gets the handle. The window caption does not change and I and neither does the class name. Please let me know if you need anymore details about the situation to me solve this issue. Another way I have confirmed that it is finding the handle correctly is I have run the second Sub (PH_Close) and it consistently finds and closes the correct window.
Closeprocess api vba code#
I have stepped through to code and it apears to find the handle correctly, but when it comes time to execute SetWindowPos, most of the time nothing happens. The problem I am having is that the window is not consistently being put on top. If WinWnd 0 Then Call PostMessage(WinWnd, WM_CLOSE, 0&, 0&) SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZEĮlse: MsgBox ("You entered a blank. WinWnd = FindWindow(vbNullString, sWndTitle) SWndTitle = InputBox("Enter at least one word from the Window Title:") Private Function StripNull(ByVal InString As String) As Stringĭim WinWnd As Long, sWndTitle As String, RetVal As Long, lpClassName As String If InStr(sTitle, psAppNameContains) > 0 Then Private Function CheckForInstance(ByVal lhWnd As Long, ByVal _ LRet = EnumWindows(AddressOf CheckForInstance, 0)
Public Function apptitlebystringpart(StringPart As String) As Boolean (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Longĭeclare Function SetWindowPos Lib "user32" ( _ (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Longĭeclare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _ĭeclare Function GetWindow Lib "user32" (ByVal hwnd As Long, _ĭeclare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, _ĭeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Longĭeclare Function GetClassName Lib "user32" Alias "GetClassNameA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Longĭeclare Function PostMessage Lib "user32" Alias "PostMessageA" _ Since the name of the window I want on top will change, I took a suggestion from NateO to enter a portion of the title to find the handle:ĭeclare Function FindWindow Lib "user32" Alias "FindWindowA" _ I have been tying to keep a window on top of Excel.