vba7 error

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,060
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

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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,215,688
Messages
6,126,209
Members
449,299
Latest member
KatieTrev

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top