Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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_Runtimeexception_Vba - Fatal编程技术网

Excel VBA编程中出错-多个工作簿

Excel VBA编程中出错-多个工作簿,excel,runtimeexception,vba,Excel,Runtimeexception,Vba,我正试图解析几个Excel文件,并将数据复制到当前打开的文件中。这是我的密码。它在这条线上失败了; dstDecTbl(rowNdx,DstDecDeath).Value=srcDecData(SrcDecDeath).Value 我可以在不同的工作簿中设置范围并参考它们吗 Option Explicit Private Const ConstModuleName As String = "ProcessModule" Public Sub BuildReport() Dim src

我正试图解析几个Excel文件,并将数据复制到当前打开的文件中。这是我的密码。它在这条线上失败了; dstDecTbl(rowNdx,DstDecDeath).Value=srcDecData(SrcDecDeath).Value 我可以在不同的工作簿中设置范围并参考它们吗

Option Explicit

Private Const ConstModuleName As String = "ProcessModule"


Public Sub BuildReport()

  Dim srcBook As Workbook
  Dim dstBook As Workbook

  Dim fileSys As Object
  Dim fileDir As Object
  Dim fileObj As Object
  Dim fileCnt As Integer

  Dim srcDecData As Range
  Dim srcCntData As Range

  Dim dstDecTbl As Range
  Dim dstCntTbl As Range

  Dim fileNdx As Integer
  Dim rowNdx As Integer


  On Error GoTo Exception

    Set dstBook = Application.ThisWorkbook
    Set dstDecTbl = dstBook.Sheets(DstPage).Range(DstDecRange)
    Set dstCntTbl = dstBook.Sheets(DstPage).Range(DstCntRange)

    Set fileSys = CreateObject("Scripting.FileSystemObject")
    Set fileDir = fileSys.GetFolder(DftSourceDir)

    rowNdx = 1
    fileNdx = 1
    For Each fileObj In fileDir.Files

      dstBook.Sheets(DstPage).Range(DstFileCount) = fileNdx
      dstBook.Sheets(DstPage).Range(DstFileName) = fileObj.Name
      Application.ScreenUpdating = False      

      Set srcBook = Workbooks.Open(fileObj.Path)
      Set srcDecData = srcBook.Sheets(SrcPage).Range(SrcDecRange)

      dstDecTbl(rowNdx, DstDecDeath).Value = srcDecData(SrcDecDeath).Value

      rowNdx = rowNdx + 1

      srcBook.Close SaveChanges:=False
      Application.ScreenUpdating = True

      fileNdx = fileNdx + 1
    Next fileObj
  Exit Sub

Exception:
    Call ExceptionModule.LogException(ConstModuleName & "." & _
                                 "buildReport", Err, vbCritical)

End Sub

忽略不计,错误在常量定义中。

当它失败时,
srcdecdeather
的值是多少?错误消息是什么?