Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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
VBA:设计模式触发和中断程序_Vba_Break_Mode - Fatal编程技术网

VBA:设计模式触发和中断程序

VBA:设计模式触发和中断程序,vba,break,mode,Vba,Break,Mode,有人遇到过这个问题吗 我正在运行的程序如下所示: 在文件夹中查找文件 从文件夹中打开文档 将表读入数组 循环到2或1 关闭文档,设置为空 将数组写入电子表格 在循环过程中,由于某种原因,我打开的文档最终触发了设计模式。这会导致退出程序的程序中断,使我失去宏所取得的进度并重新启动 我有没有办法避免这种情况发生,或者可能理解为什么?当我打开文档时,我不相信文档本身处于设计模式,只是因为某些原因触发了功能 以下是我打开文档时的代码: For f = LBound(strPaths) To UBound

有人遇到过这个问题吗

我正在运行的程序如下所示:

  • 在文件夹中查找文件
  • 从文件夹中打开文档
  • 将表读入数组
  • 循环到2或1
  • 关闭文档,设置为空
  • 将数组写入电子表格
  • 在循环过程中,由于某种原因,我打开的文档最终触发了设计模式。这会导致退出程序的程序中断,使我失去宏所取得的进度并重新启动

    我有没有办法避免这种情况发生,或者可能理解为什么?当我打开文档时,我不相信文档本身处于设计模式,只是因为某些原因触发了功能

    以下是我打开文档时的代码:

    For f = LBound(strPaths) To UBound(strPaths)
        Set Files = New Collection
        dirpath = strPaths(f)
        strFile = Dir(dirpath & "*.xls*")     ' Record file into string.
        Do While strFile <> ""
            Files.Add strFile
            strFile = Dir
        Loop
        numCSV = numCSV + Files.count
        For Each strFile In Files
            dirpath = strPaths(f)
            wbkPath = dirpath & strFile
            If InStr(1, wbkPath, "Bulk") > 0 Then GoTo NextFile
            nrow = OpenDoc(wbkPath, wbkCSV)
            If Not nrow <= 1 Then
                scopeArray(k) = PullScope(wbkCSV, wshPalette, strFile, roffset, nrow, x)
                roffset = roffset + nrow
                k = 1 + k
                ReDim Preserve scopeArray(k)
            End IfNextFile:
        Next strFile
    Next f
    
    Public Function OpenDoc(wbkPath, wbkCSV As Workbook) As Long
        Dim r As Integer
    
    ' With workbook still open, process.
        Application.AskToUpdateLinks = False
        Application.DisplayAlerts = False
        Set wbkCSV = Workbooks.Open(wbkPath)
        Application.DisplayAlerts = True
        Application.AskToUpdateLinks = True
      '  On Error GoTo NextDoc
        Set wshTemp = wbkCSV.Worksheets(1)
    
        r = WorksheetFunction.CountA(wshTemp.Columns(6)) - 1
     If r <= 1 Then
        wbkCSV.Close
        Set wbkCSV = Nothing
     End If
    OpenDoc = r
    End Function
    
    f=LBound(strPaths)到UBound(strPaths)的
    
    设置文件=新集合
    dirpath=strPaths(f)
    strFile=Dir(dirpath&“*.xls*”)将文件记录为字符串。
    当strFile“”时执行
    文件。添加strFile
    strFile=Dir
    环
    numCSV=numCSV+Files.count
    对于文件中的每个strFile
    dirpath=strPaths(f)
    wbkPath=dirpath和strFile
    如果InStr(1,wbkPath,“Bulk”)>0,则转到下一个文件
    nrow=OpenDoc(wbkPath,wbkCSV)
    
    如果不是nrow,我想我会为此提供一些更新

    我还没有确定到底是什么导致了这种情况,但我认为这可能是因为我在代码执行期间使用了我的计算机

    添加以下行停止了此错误的重复发生:

    Application.Interactive = False
    ' Code
    Application.Interactive = True
    

    我怀疑我对使用F5刷新web浏览器的上瘾可能是罪魁祸首。

    所以我想我会为此提供一些更新

    我还没有确定到底是什么导致了这种情况,但我认为这可能是因为我在代码执行期间使用了我的计算机

    添加以下行停止了此错误的重复发生:

    Application.Interactive = False
    ' Code
    Application.Interactive = True
    

    我怀疑我对使用F5刷新web浏览器的上瘾可能是罪魁祸首。

    strPaths()中的值是否以反斜杠字符结尾?你似乎把那部分从你的帖子里漏掉了。确实如此。这会产生一些影响吗?它们的格式是“C:\Folder\Subfolder\”
    strPaths()
    中的值是否以反斜杠字符结尾?你似乎把那部分从你的帖子里漏掉了。确实如此。这会产生一些影响吗?它们的格式是“C:\Folder\Subfolder\”