I am having problems with the following script.
It errors on this line of script and if I change any of the ptrlong's then it errors on a different part
It errors on this line of script and if I change any of the ptrlong's then it errors on a different part
Code:
Caption = IIf(L > 0, Left(Caption, L), "")
Code:
#If VBA7 Then
Private Declare PtrSafe Function GetDesktopWindow _
Lib "User32.dll" () As LongPtr
Private Declare PtrSafe Function GetWindow Lib "User32.dll" _
(ByVal hwnd As LongPtr, ByVal wCmd As LongPtr) As LongPtr
Private Declare PtrSafe Function GetWindowText Lib "User32.dll" _
Alias "GetWindowTextA" (ByVal hwnd As LongPtr, _
ByVal lpSting As String, ByVal nMaxCount As LongPtr) As LongPtr
Function IsWindowOpen(ByVal Window_Caption As String) As Boolean
Dim Caption As String
Dim CurrWnd As LongPtr
Dim L As LongPtr
Const GW_CHILD As LongPtr = 5
Const GW_HWNDNEXT As LongPtr = 2
' Start with the Top most window that has the focus
CurrWnd = GetWindow(GetDesktopWindow, GW_CHILD)
' Loop while the hWnd returned by GetWindow is valid.
While CurrWnd <> 0
' Get Window caption
Caption = String(64, Chr$(0))
L = GetWindowText(CurrWnd, Caption, 64)
Caption = IIf(L > 0, Left(Caption, L), "")
End Function
#Else
Private Declare Function GetDesktopWindow _
Lib "User32.dll" () As Long
Private Declare Function GetWindow Lib "User32.dll" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "User32.dll" _
Alias "GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpSting As String, ByVal nMaxCount As Long) As Long
Function IsWindowOpen(ByVal Window_Caption As String) As Boolean
Dim Caption As String
Dim CurrWnd As Long
Dim L As Long
Const GW_CHILD As Long = 5
Const GW_HWNDNEXT As Long = 2
' Start with the Top most window that has the focus
CurrWnd = GetWindow(GetDesktopWindow, GW_CHILD)
' Loop while the hWnd returned by GetWindow is valid.
While CurrWnd <> 0
' Get Window caption
Caption = String(64, Chr$(0))
L = GetWindowText(CurrWnd, Caption, 64)
Caption = IIf(L > 0, Left(Caption, L), "")
End Function
#End If