我的 VBA 代码有一些问题。这就是我想要做的:
- 从工作表中获取路径(输入)
- 打开相关工作簿
- 使用高级过滤器仅将已打开文件的 60 多个所需列复制到原始文件中。
- 关闭文件
我知道到目前为止代码部分是硬编码的并且有些臃肿,但请忽略它。
当我运行 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