VBA:将单元格从一个工作簿复制到另一个工作簿会产生空白结果

时间:2014-07-24 17:06:13

标签: excel vba excel-vba

我有四个子程序,每个子程序都接受一个指定的外部文件,并将该文件中的工作表复制到子运行的工作簿中的工作表中。对于3/4潜艇,这很好用。然而,第四个子目录在目的地给我空白结果。所有四个子代码的代码都是相同的,只是文件名已更改。我看到的可能导致此错误的最大区别是有问题的源工作簿受到保护。我正在使用我的sub解锁它,然后复制文件。将手表添加到源会显示整个范围为" Variant / Empty"

' declare variables
    Dim financialReportBook As Workbook
    Set financialReportBook = Workbooks.Open(FileNavPrompt.financialFilePath)
    Dim financialSheet As Worksheet
    Set financialSheet = FileNavPrompt.mainBook.Sheets("Financial Status")
    Dim copyRange As String
    copyRange = "A1:AA5000"

' unprotect workbook
    financialReportBook.Unprotect ("{password removed}")          ' unprotect workbook for copying

' pull data from report
    financialSheet.Cells.Clear      ' start with a clean slate
    financialSheet.Range(copyRange).Value = financialReportBook.Sheets(1).Range(copyRange).Value
    financialSheet.Range(copyRange).NumberFormat = financialReportBook.Sheets(1).Range(copyRange).NumberFormat                                

' close report
    financialReportBook.Close False

' unrelated code continues below...

1 个答案:

答案 0 :(得分:0)

最根本的问题是,源工作簿将索引1的表单归为xlVeryHidden。当我将第一张可见纸张作为索引1而不是实际上的索引2处理时,这会造成混淆。