currentFolder=CreateObject("wscript.shell").currentDirectory&""
filename1=currentFolder&"Domino.xlsx"
filename2=currentFolder&"SAP.xlsx"
filename3=currentFolder&"执行后生成的文件.xlsx"
Set dic=CreateObject("scripting.dictionary")
Set excelObject=CreateObject("Excel.Application")
Set workbook1=excelObject.Workbooks.Open(filename1)
Set workbook2=excelObject.Workbooks.Open(filename2)
Set workbook3=excelObject.Workbooks.Add
Set workbook1_sheet=workbook1.Sheets("Sheet1")
Set workbook2_sheet=workbook2.Sheets("Sheet1")
Set workbook3_sheet=workbook3.Sheets("Sheet1")
workbook1_rowcount=workbook1_sheet.usedrange.rows.count
For i=0 To workbook1_rowcount
content=workbook1_sheet.range("A1").offset(i,0).value
If Not dic.Exists(content) Then
dic.Add content,content
End If
Next
workbook2_rowcount=workbook2_sheet.usedrange.rows.count
workbook2_columncount=workbook2_sheet.usedrange.columns.count
sheet3_row=0
For i=0 To workbook2_rowcount
content=workbook2_sheet.range("A1").offset(i,0).value
If dic.Exists(content) Then
For j=0 To workbook2_columncount
workbook3_sheet.range("A1").offset(sheet3_row,j).value=workbook2_sheet.range("A1").offset(i,j).value
Next
sheet3_row=sheet3_row+1
End If
Next
workbook3.SaveAs(filename3)
workbook3.Close
workbook2.Close
workbook1.Close
Set workbook3=Nothing
Set workbook2=Nothing
Set workbook1=Nothing
Set excelObject=Nothing
Set dic=nothing
MsgBox "finish"1. 准备好两个对比文件文件命令建议使用以下名称:1和2
1.Excel1文件内容:
2.Excel2文件内容:
2. 然后将脚本放入文件同一目录,双击执行
3. 双击执行,提示Finish,然后会在当前目录生成命名为:执行后的生成文件
4. 打开生成的文件,查看结果: