I'm copying data form one workbook to another workbook and then run a macro from the copied workbook. The below VBA code works fine.
VBA Code
Sub test()
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks.Open("D:\mywork\work_data.xlsx")
Set y = Workbooks.Open("D:\mywork\other_work_data.xlsm")
x.Sheets("myworksheet").UsedRange.Copy
y.Sheets("Sheet1").Range("A1").PasteSpecial
y.Save
x.Close
Application.Run ("other_work_data.xlsm!checkDate")
y.Close
End Sub
Now, I'm trying to change the following vba
code to vbscript
, but it doesn't work for me.
VBScript code
Sub test()
Dim ExcelApp
Dim x
Dim y
Set ExcelApp = CreateObject("Excel.Application")
Set x = ExcelApp.Workbooks.Open("D:\mywork\work_data.xlsx")
Set y = ExcelApp.Workbooks.Open("D:\mywork\other_work_data.xlsm")
x.Sheets("myworksheet").UsedRange.Copy
y.Sheets("Sheet1").Range("A1").PasteSpecial
y.Save
x.Close
ExcelApp.Application.Run ("other_work_data.xlsm!checkDate")
y.Close
ExcelApp.DisplayAlerts = False
ExcelApp.Application.Quit
Set ExcelApp = Nothing
End Sub
Since I'm new to vba
and vbscript
, can anyone tell me what I'm doing wrong? I had gone through similar questions in stack overflow, but I didn't sort out the issue.