Compile Error: Sub or Function not defined

TheHagrid

New Member
Joined
May 4, 2014
Messages
8
Hi Gurus,

I'm working on a dashboard of sorts and everything was working until I added this code which was to run and advanced filter, whilst prior to running the Adv Filter it checks to see if the file is open, and open if it is not.

"Call SupStatsLoad" Hilighted in Blue and error given at the begining of the referring from Sub

Basic References loaded Office Forms 14, Excel Forms 14, Forms 2.0 library, Ole Automation, and VBA.

Added Code located in Module and called from Workbook_Open
Code:
    Call SupStatsLoad(SupMax)

referred to Functions which is located in the Adv Filter Sheet
Code:
Public Function SupStatsLoad(Max As Variant)
    'Test if SupWB is open
    SupWB = "CC_" & Max & ".xlsm"
    Application.ScreenUpdating = False
    If WorkbookOpen(SupWB) = False Then
        Application.DisplayAlerts = False
        Workbooks.Open Filename:="CorrectFile location :) \zzzBackup\CC_" & Max & ".xlsm, IgnoreReadOnlyRecommended:=True, UpdateLinks:=False"
        Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End If
    
    Workbooks(SupWB).Sheets("SupStats").Range("E31:J51" _
        ).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("A1:AF2"), _
        CopyToRange:=Range("A3:AF3"), Unique:=False
    
    Workbooks(SupWB).Close saveChanges:=False
    Workbooks("MGO Overview.xlsb").Activate
End Function
Function WorkbookOpen(WorkBookName As String) As Boolean
'returns true if the workbook is open
WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
    WorkbookOpen = True
    Exit Function
End If
WorkBookNotOpen:
End Function

Any Help would be greatly appreciated,
Regards,
TheHagrid
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Put the code in a standard module, not a sheet module and change Function SupStatsLoad to Sub SupStatsLoad.
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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