Blockinput VBA/EXCEL

Asked

Viewed 123 times

0

I need to lock the commands in my macro in Excel. I am using the following function:

Public Declare Function BlockInput Lib "user32" (ByVal fblock As Long) As Long

On the computer with 64 bit win works normally but when I passed the spreadsheet to a 32 bit PC the blockinput function stopped working, but without presenting any error and the rest of the program works normally. It is extremely necessary for me to work this function and block the input after the macro execution, even on 32 bit Pc. Any idea what might be going on? Thank you!

  • According to the function documentation Blockinput It only works on Windows 2000 Professional platforms for the Client and Windows 2000 Server layers for the Server layers. The documentation does not mention limitations as to the word size, but understands that this function is supported on 32-bit word machines because function is stated in the library User32.dll.

1 answer

0

With a test to check the Windows version and the Office package:

'https://stackoverflow.com/a/27931754/7690982
Sub versao()
    #If Win64 Then
        #If VBA7 Then
            MsgBox "Win 64 and Office 64"        ' HKEY_LOCAL_MACHINE\SOFTWARE\YourApp
        #Else
            MsgBox "Win 64 and Office 32"        ' HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\YourApp
        #End If
    #Else
        MsgBox "Win 32 and Office 32"            ' HKEY_LOCAL_MACHINE\SOFTWARE\YourApp
    #End If
End Sub

The Office and Windows test are 32 bits and the following code worked for the BlockInput:

Option Explicit

#If VBA7 Then
    Public Declare PtrSafe Function BlockInput Lib "User32" (ByVal fBlock As Boolean) As Boolean '64 Bit
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) '64 Bit
#Else
    Public Declare Function BlockInput Lib "User32" (ByVal fBlock As Boolean) As Boolean '32 Bit
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '32 Bit
#End If

Sub teste_blockinput()
    On Error GoTo Sair
    BlockInput (True)
    'Código Aqui
    Sleep 10000 'Sleep de 10 segundos
Sair:
    BlockInput (False)
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.