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

leighhobson89

New Member
Joined
Aug 25, 2016
Messages
36
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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi

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

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

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