高级筛选器以复制到另一个工作簿上

时间:2013-10-31 13:56:10

标签: excel vba excel-vba

我的VBA代码存在一些问题。 这就是我想要做的事情:

  1. 从工作表(输入)
  2. 获取路径
  3. 打开相关工作簿
  4. 使用高级过滤器仅将超过60个已打开文件的所需列复制到原始文件。
  5. 关闭文件
  6. 我知道代码到目前为止部分是硬编码的并且有些臃肿,但请忽略它。

    当我运行vba时,我在高级过滤器行中收到运行时错误438.(不支持属性或方法)。

    这是我的代码:

    Public strFileName As String
    Public currentWB As Workbook
    Public dataWB As Workbook
    Public strCopyRange As String
    Public rngFiltro As Variant
    
    Sub PrendiDati()
        Dim strListSheet As String
        Dim rngFonte As Variant
    
    
        strListSheet = "input"
    
        'On Error GoTo ErrH
        Application.Calculation = xlCalculationManual
        ActiveWorkbook.Worksheets("SCADENZIARIO").Range("A2:R15000").Clear
        Sheets(strListSheet).Select
        Range("b6").Select
    
        'this is the main loop, we will open the files one by one and copy their data into the masterdata sheet
        Set currentWB = ActiveWorkbook
            strFileName = ActiveCell.Offset(0, 1) & ActiveCell.Value
            strCopyRange = ActiveCell.Offset(0, 2) & ":" & ActiveCell.Offset(0, 3)
            strWhereToCopy = ActiveCell.Offset(0, 4).Value
            strStartCellColName = Mid(ActiveCell.Offset(0, 5), 2, 1)
            Application.Workbooks.Open strFileName, UpdateLinks:=False
            Set dataWB = ActiveWorkbook
            dataWB.Worksheet(1).Range("Database").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=currentWB.Sheets("SCADENZIARIO").Range("A1")
            Application.CutCopyMode = False
            dataWB.Close False
            Sheets(strListSheet).Select
            Exit Sub
    

1 个答案:

答案 0 :(得分:0)

您的代码中有拼写错误:

dataWB.Worksheet(1)

应该是:

dataWB.Worksheets(1)

错误引发,因为Worksheet对象现在有Workbook属性/方法。