title: VBA Script Error: "Sub or Function not defined"
body: <p>I have written the following code which is supposed to open up a specified windows directory and then one by one process all Excel (.xls) files in that location.  To be more specific the code will open an excel file, take the name given to the worksheet and place that name/value into cell A1 of that worksheet and then save and close the file.  It will then move onto the next Excel file in the directory.</p>
  
  <p>The problem I face is that on executing the code I get the following compile error: "Sub or Function not defined".  I am just unable to figure out what is causing this error.</p>
  
  <p>Please see code witten below:</p>
  
  <pre><code>Sub UseSheetName()
      selectedfolder = GetFolder("c:\")
      Call updateAllWorkbooks(selectedfolder)
  End Sub
  
  Function GetFolder(strPath As String) As String
      Dim fldr As FileDialog
      Dim sItem As String
      Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
      With fldr
          .Title = "Select a Folder"
          .AllowMultiSelect = False
          .InitialFileName = strPath
  
          If .Show &lt;&gt; -1 Then GoTo NextCode
              sItem = .SelectedItems(1)
      End With
  
  NextCode:
      GetFolder = sItem
      Set fldr = Nothing
  End Function
  
  Function updateAllWorkbooks(workDir)
      Dim fso, f, fc, fl
      Dim newName As String, appStr As String, SubDir As String
  
      On Error GoTo updateAllWorkbooks_Error
  
      SubDir = workDir &amp; "\" &amp; "ConvertedFiles"
      If Not fExists(SubDir) Then
          MkDir SubDir
      End If
  
      Application.ScreenUpdating = False
  
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f = fso.GetFolder(workDir)
      Set fc = f.Files
  
      For Each fl In fc
          If Right(fl, 4) = ".xls" Then
              Application.DisplayAlerts = False
              Workbooks.Open Filename:=fl
              ActiveSheet.[a1] = ActiveSheet.Name
              ActiveWorkbook.Save
              ActiveWorkbook.Close
              Application.DisplayAlerts = True
          End If
      Next
  
      Application.ScreenUpdating = True
  
      On Error GoTo 0
      Exit Function
  
  updateAllWorkbooks_Error:
      MsgBox "Error " &amp; Err.Number &amp; " (" &amp; Err.Description &amp; ") in procedure updateAllWorkbooks of Module Module2"
  End Function
  </code></pre>