我有以下几个已经工作了几个月:
Sub copy_over_csv_files()
Application.ScreenUpdating = False
Dim wbName As String: wbName = ThisWorkbook.Name
Dim totalSheets As Integer:
Dim filePath As String ' used to hold file path for finding the needed csv file
Dim fileName As String
Dim fileNameArray() As Variant
ReDim fileNameArray(9)
fileNameArray = Array("x.csv", _
"y.csv", "z.csv", _
"n.csv", "q.csv", _
"r.csv", "s.csv", _
"a.csv", "b.csv", "c.csv")
Dim n As Integer ' counter for file names array loop
For n = 0 To 9
totalSheets = Workbooks(wbName).Sheets.Count
filePath = "Macintosh HD:Users:file1:file2:file3:" & fileNameArray(n)
ChDir "Macintosh HD:Users:file1:file2:file3:"
Workbooks.Open fileName:=filePath ' file path to needed file
Sheets(fileNameArray(n)).Select
Sheets(fileNameArray(n)).Copy After:=Workbooks(wbName).Sheets(totalSheets)
Windows(fileNameArray(n)).Activate
ActiveWorkbook.Close
ActiveWorkbook.Save
Next n
Application.ScreenUpdating = True
End Sub
然后我写了以下函数:
Function GetAgentEmailWorksheet(AgentObjectId As String)
Dim specific_agent As clsAgent
Set specific_agent = New clsAgent
specific_agent.AgentSheetName = "agentsFullOutput.csv"
Dim id_array() As Variant
id_array = specific_agent.AgentIDArray
Dim email_array() As Variant
email_array = specific_agent.AgentEmailArray
GetAgentEmailWorksheet = vlook_using_array(AgentObjectId, id_array, email_array)
End Function
出于某种原因,第一个子组中的以下行:Sheets(fileNameArray(n)).Copy After:=Workbooks(wbName).Sheets(totalSheets)
打开该函数。
我不知道为什么,我也不知道如何让它停止。