0

When this code:

Public Declare Function BringWindowToTop Lib "user32" _
Alias "BringWindowToTop" (ByVal hwnd As Long) As Long

Shows the error:

Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of an object module

Please help me to resolve error

June7
  • 19,874
  • 8
  • 24
  • 34
abbas
  • 1
  • 1
    The error msg tells you. `Declare` can't go in form module, it must be in code module. – Andre Feb 06 '21 at 23:49
  • Code module AKA general module, i.e. not behind form or report. – June7 Feb 06 '21 at 23:52
  • More info https://stackoverflow.com/questions/46428459/declare-statement-in-win64-vba-office – June7 Feb 07 '21 at 00:00
  • In addition to ensuring that the declaration is in a standard code module, are you sure that you don't need a *PtrSafe* version of the API? – Variatus Feb 07 '21 at 01:05

1 Answers1

0

In a module (not a form):

#If VBA7 Then
    Public Declare PtrSafe Function BringWindowToTop Lib "user32" _
        (ByVal hwnd As Long) As Long
#Else
    Public Declare Function BringWindowToTop Lib "user32" _
        Alias "BringWindowToTop" (ByVal hwnd As Long) As Long
#End If
DerinNehir
  • 56
  • 6