What find of function can go under Workbook_BeforeSave

Viewed 21

So I have 2 functions in my Modules folder:

Sub update_range(namedRange As String)
    Dim rangeData As Range
    Dim startRow As Integer

    Set rangeData = ThisWorkbook.Names(namedRange).RefersToRange
    startRow = rangeData.Row
    Set rangeData = rangeData.CurrentRegion
    
    If rangeData.Row < startRow Then
        Dim extraTopRow As Integer
        extraTopRow = startRow - rangeData.Row
        Set rangeData = rangeData.Resize(rangeData.Rows.Count - extraTopRow)
        Set rangeData = rangeData.Offset(extraTopRow)
    End If
    rangeData.Name = namedRange
End Sub

Sub update_all_ranges()
    update_range ("range1")
    update_range ("range2")
End Sub

Inside my ThisWorkbook, if do this:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    update_range ("range1")
    update_range ("range2")
End Sub

It works.

But if I do this:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    update_all_ranges()
End Sub

I get a

compilation error:

Syntax error

popup box.

Why is that? How do I fix it?

0 Answers
Related