脚本独立运行,但不能作为更大程序的子例程

Script works on its own but not as a subroutine of a bigger program

我写了下面的代码,测试了它,它可以工作。然后我从字面上将其作为子程序复制并粘贴到一个更大的程序中。我现在在 Split Function 上遇到类型不匹配问题。我将它从子例程中复制并粘贴到一个新文件中,然后它再次运行。任何关于为什么会发生这种情况的帮助将不胜感激。

Dim oFSO
Dim oNew
Dim oExcel
Dim Folder2
Dim oFile
Dim File, Line
Dim f, fc
Dim x, y, e, i, j 
Dim objSheet, TFile, TSheet
Dim TextLine


'Calls Excel into session and leaves it running in the background
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = False
oExcel.DisplayAlerts = False

'Opens the selected excel file and then lets the user choose the folder to be updated to it

Set oNew = oExcel.Workbooks.Open(BrowseForFolder("Select Excel File to Update"))  
Set oFSO = CreateObject("Scripting.FileSystemObject")
Folder2 = BrowseForFolder("Choose file containing updated CSV's")
Set f = oFSO.GetFolder(Folder2)
Set fc = f.Files
oNew.Activate

'This loops through every file in the folder, compares the name of the file to the names
'of the sheets in the excel file and overwrites the data to on the spreadsheet
For Each oFile In fc
    TFile = Left(oFile.Name,InStr(oFile.Name,"-")-1)
    For i =1 To oNew.Sheets.Count
        j = InStr(oNew.Sheets(i).Name,"-")-1
        TSheet = Left(oNew.Sheets(i).Name,j)
        if  TSheet = TFile Then
            oNew.Sheets(i).Activate
            set objSheet = oNew.ActiveSheet
            objSheet.Name = Left(oFile.Name,InStr(oFile.Name,".")-1)
            Set File = oFSO.OpenTextFile(oFile)
            x = 1

            Do While File.AtEndofStream <> True
                Line = File.Readline
                TextLine = Split(Line,",")
                y = 1
                For Each e In TextLine
                    objSheet.Cells(x, y) = e
                    y = y+1
                Next
                x=x+1
            Loop
        End If
    Next
Next        

MsgBox "Spreadsheet Updated! New spreadsheet is located in Documents"

' Save merged result as an Excel file in Documents

oNew.SaveAs "SAPDASHBOARD", 51
oNew.Close

' Shut down Excel
oExcel.Quit

Set oExcel = Nothing
Set oNew = Nothing
Set oFile = Nothing

Function BrowseForFolder(title)
Dim shell : Set shell = CreateObject("Shell.Application")
Dim file : Set file = shell.BrowseForFolder(0, title, &H4000,0)
If file is Nothing Then
    WScript.Echo "No Folder Selected"
    WScript.Quit
End IF
BrowseForFolder = file.self.Path
End Function

我真的想通了。问题不在于脚本的这一部分,而是大程序中的其他子例程之一名为 Split 的事实。因此,当它尝试 运行 内置函数 "Split" 时,它会尝试调用子例程。这是我不会再犯的错误