Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无意中调用函数excel vba_Excel_Vba - Fatal编程技术网

无意中调用函数excel vba

无意中调用函数excel vba,excel,vba,Excel,Vba,我有以下工作了几个月的分包商: 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

我有以下工作了几个月的分包商:

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:=工作簿(wbName).Sheets(totalSheets)
打开该功能


我不知道为什么,也不知道如何让它停止。

您必须给我们提供足够的信息来重现问题,否则我们将无能为力。请参阅此指南:现在我只能随机猜测:您是否有
工作簿\新闻单
活动?我很抱歉没有信息,但我不想发布整个课程…等等。似乎代码太多了。我不知道什么是新闻单,但我的意思是:那么,不,我不知道。我希望有人能解释一个函数是如何在没有直接在代码中被调用的情况下被调用的。这看起来真的很奇怪,而且作为一种行为是不可能的。我会说:1)检查所有事件,看看函数在哪里被调用,并试着理解为什么;2) 调试代码,告诉我们在调用代码行和进入函数(是直接的还是通过其他代码)之间发生了什么;3) 确保没有阴影代码(有时,如果你不编译,可能是在VBE上你看到了一些东西,但编译后的代码在这一部分包含了其他东西。@dwstein:我不想让你发布整个类。相反,你读了我给你的链接了吗?它是关于创建重现问题所需的最小示例,即只需要几行代码尽可能。这样很好,很孤立,也很容易诊断。如果你希望我们花点时间帮助你,请花点时间阅读。