Could someone please tell me why the following VB script works fine if executed from within excel but won't work if it executed using the cmd: cscript c:\vb\test.vbs?. Below is my code I'm trying to get it working using the cmd. I'm using excel .xls (excel 97-2003).
Private Sub CopyData()
Dim x
Dim y
'## Open both workbooks first:
Set x = Workbooks.Open("C:\VB\CopyDataTest.xls")
'Now, copy what you want from x:
Sheets("Sheet1").Range("A:B").Copy
Set y = Workbooks.Open("C:\VB\Destination.xls")
'Now, paste to y worksheet:
y.Sheets("Sheet2").Range("A:B").PasteSpecial
'Close x:
y.Close
End Sub