Sleep API conversion 32 / 64 bit

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I want to find a conversion for the Sleep API.

Should it be:
Rich (BB code):
#If  VBA7 Then ' Excel 2010 or later
 
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
 
#Else  ' Excel 2007 or earlier
 
    Public Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
 
#End  If
or
Rich (BB code):
#If  Win64 Then
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else 
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
   
#End  If

I have seen another API and it's very complicted:
Rich (BB code):
#If  VBA7 Then    ' (OFFICE 2010 AND LATER - Either 32bit or 64bit Editions)
    
        Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
                                                                                      ByVal lpWindowName As String) As LongPtr
    
        #If  Win64 Then   '(64bit OS) AND (64bit Office)
        
            Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hWnd As LongPtr, _
                                                                                                   ByVal nIndex As Long) As LongPtr
                                                                                                   
            Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hWnd As LongPtr, _
                                                                                                   ByVal nIndex As Long, _
                                                                                                   ByVal dwNewLong As LongPtr) As LongPtr
        
        #Else     ' (32 or 64 bit OS) AND (32bit Office)
            
            Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, _
                                                                                                ByVal nIndex As Long) As Long
                                                                                                
            Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, _
                                                                                                ByVal nIndex As Long, _
                                                                                                ByVal dwNewLong As Long) As Long
         
         #End  If
    
    #Else     ' (OFFICE 2007 AND BEFORE)  .. Both (32bit OS) AND (32bit Office)
    
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
                                                                              ByVal lpWindowName As String) As Long
                                                                              
        Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, _
                                                                                    ByVal nIndex As Long) As Long
                                                                                    
        Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, _
                                                                                    ByVal nIndex As Long) As Long
    
    #End  If
    
    Private Const WS_SYSMENU = &H80000
    Private Const GWL_STYLE = (-16)
Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
As far as I know, the correct declaration is:
Rich (BB code):
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
#Else 
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
#End  If
 
Upvote 0
As far as I know, the correct declaration is:
Rich (BB code):
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
#Else 
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
#End  If


Thanks


Will that take care of all the combinations, ie?


OFFICE 2010 AND LATER - Either 32bit or 64bit Editions
(32 or 64 bit OS) AND (32bit Office)
(OFFICE 2007 AND BEFORE) .. Both (32bit OS) AND (32bit Office)
 
Upvote 0
Thanks


Will that take care of all the combinations, ie?


OFFICE 2010 AND LATER - Either 32bit or 64bit Editions
(32 or 64 bit OS) AND (32bit Office)
(OFFICE 2007 AND BEFORE) .. Both (32bit OS) AND (32bit Office)

Yes.
 
Upvote 0
Either of your two options should work for Sleep.
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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