Error: "Only comments may appear after End Sub, End Function, or End Property"

leighhobson89

New Member
Joined
Aug 25, 2016
Messages
33
Good Morning guys!

Looking at the following code (which will have a procedure under the IF statement eventually), cn anyone tell me why already I am receiving the error in the title of this post?

Code:
Sub CheckVBAVersion()
'Open an instance of each required app

' Test which version of VBA you are using.

#If VBA7 Then
   ' API function to locate a window.
   Declare PtrSafe Function FindWindow Lib "user32" _ [COLOR=#ff0000]'THIS BLOCK OF CODE[/COLOR]
      Alias "FindWindowA" ( _                                   [COLOR=#ff0000]'IS HIGHLIGHTED[/COLOR]
      ByVal lpClassName As String, _                         [COLOR=#ff0000]' WHEN ERROR[/COLOR]
      ByVal lpWindowName As String) As LongPtr         [COLOR=#ff0000]' IS THROWN[/COLOR]
    
   ' API function to retrieve a window's dimensions.
   Declare PtrSafe Function GetWindowRect Lib "user32" ( _
      ByVal hwnd As LongPtr, _
      lpRect As RECT) As Long

#Else
   ' API function to locate a window.
    Declare Function FindWindow Lib "user32" _
      Alias "FindWindowA" ( _
      ByVal lpClassName As String, _
      ByVal lpWindowName As String) As Long
    
   ' API function to retrieve a window's dimensions.
    Declare Function GetWindowRect Lib "user32" ( _
      ByVal hwnd As Long, _
      lpRect As RECT) As Long
    
#End If

End Sub

I can't see any problems that are causing this specific error. Moreover, I have tried adding "End Function" to each Function to no avail.

Please help!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
Hi

Declare statements are used at module level.
Move the code between the #If to the #End If to the beginning of the module.
 

Forum statistics

Threads
1,176,255
Messages
5,902,171
Members
434,945
Latest member
ngabrieln

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
Top