将唯一数据从一个 excel 复制到另一个时,获取范围 class 的 AdvancedFilter 方法失败错误
Getting AdvancedFilter method of range class failed error while coping unique data from one excel to another
我附上了 excel 文件的片段,其中 B 列是所需的输出。这种类似的逻辑在宏中有效,但根据我们的要求,我们需要为其构建一个 VBScript。下面是我的代码
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set inputExcelWorkbook = oExcel.Workbooks.Open("C:\...\Test1.xlsx")
Set inputExcelSheet = inputExcelWorkbook.ActiveSheet
inputExcelSheet.Range("A2:A11").AdvancedFilter _
xlFilterCopy,,inputExcelSheet.Range("B2"),True
inputExcelWorkbook.save
inputExcelWorkbook.close
Excel 文件的片段
所以,当我没有使用 xlFilterCopy 时,我的问题得到了解决,我根据@nick.McDermaid 建议
使用了“2”
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set inputExcelWorkbook = oExcel.Workbooks.Open("C:\...\Test1.xlsx")
Set inputExcelSheet = inputExcelWorkbook.ActiveSheet
inputExcelSheet.Range("A2:A11").AdvancedFilter _
2,,inputExcelSheet.Range("B2"),True
inputExcelWorkbook.save
inputExcelWorkbook.close
我附上了 excel 文件的片段,其中 B 列是所需的输出。这种类似的逻辑在宏中有效,但根据我们的要求,我们需要为其构建一个 VBScript。下面是我的代码
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set inputExcelWorkbook = oExcel.Workbooks.Open("C:\...\Test1.xlsx")
Set inputExcelSheet = inputExcelWorkbook.ActiveSheet
inputExcelSheet.Range("A2:A11").AdvancedFilter _
xlFilterCopy,,inputExcelSheet.Range("B2"),True
inputExcelWorkbook.save
inputExcelWorkbook.close
Excel 文件的片段
所以,当我没有使用 xlFilterCopy 时,我的问题得到了解决,我根据@nick.McDermaid 建议
使用了“2”Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set inputExcelWorkbook = oExcel.Workbooks.Open("C:\...\Test1.xlsx")
Set inputExcelSheet = inputExcelWorkbook.ActiveSheet
inputExcelSheet.Range("A2:A11").AdvancedFilter _
2,,inputExcelSheet.Range("B2"),True
inputExcelWorkbook.save
inputExcelWorkbook.close