Below is the VBScript code for deleting the duplicates from one excel workbook and then copying it to another, when I run it I'm getting an error;
Object required:Activesheet
This is the code:
Set objExcel = CreateObject("Excel.Application")
' Open the workbook
Set objWorkbook1 = objExcel.Workbooks.Open("C:\Users\vijendra\Desktop\duplicates.xlsx")
Macro
Sub Macro1()
activesheet.UsedRange.RemoveDuplicates Columns=Array(), Header=xlYes
End Sub
'Opening the 2nd workbook
Set objworkbook2 = objExcel.Workbooks.Open("C:\Users\vijendra\Desktop\test2.xlsx")
'Set to True or False, whatever you like
objExcel.Visible = True
'Select the range on Sheet1 you want to copy
objWorkbook1.Worksheets("Sheet1").usedrange.Copy
'Paste it on sheet1 of workbook2, starting at A1
objWorkbook2.Worksheets("Sheet1").Range("A1").PasteSpecial
'Activate Sheet2 so you can see it actually pasted the data
objWorkbook2.Worksheets("Sheet1").Activate
VBScript doesn't support implicit use of the application object. You have to use it explicitly. VBScript also doesn't support named arguments (
name:=value
) or Excel built-in constants (xlYes
). Change this line:into this: