0

I am struggling a little bit copy pasting cells from one Excel to another Excel file using another software. I have the following code (which I borrowed it from this thread) here:

Set objExcel = CreateObject("Excel.Application")

' Variables passed on from a software
' vTempRange is "A2:D14" and vFinalRange is something similar
vTempRange = WScript.Arguments.Item(0)
vFinalRange = WScript.Arguments.Item(1)
vReport = WScript.Arguments.Item(2)

' Open the workbook
Set x = Workbooks.Open("C:\sample.xlsx")
Set y = Workbooks.Open("C:\Final.xlsx")
' Set to True or False, whatever you like
objExcel.Visible = True

' Select the range on Sheet1 you want to copy 
x.Worksheets("Sheet1").Range(vTempRange).Copy
' Paste it on Sheet2, starting at A1
y.Worksheets(vReport).Range(vFinalRange).PasteSpecial
' Activate Sheet2 so you can see it actually pasted the data
y.Worksheets(vReport).Activate 

However, this returns me a 424 object required error when running through the other software. Could anybody give me some hints or solutions for this? Thank you!

user116922
  • 51
  • 5
  • 2
    `Set x = objExcel.Workbooks.Open(...) : Set y = objExcel.Workbooks.Open(...)`? – 41686d6564 stands w. Palestine Jul 08 '19 at 00:54
  • The "right" way to solve a problem like this is to debug it and step through it until you reach the error. Then it would be obvious that "Workbooks" is not initialized. Now it seems like you are flying blind and asking us which tree you hit. – Geert Bellekens Jul 08 '19 at 06:48
  • @GeertBellekens Note that this is VBScript, not VBA and not everyone has the tools/knowledge to debug and step through some VBScript code (just to be fair to the OP). – 41686d6564 stands w. Palestine Jul 08 '19 at 11:57
  • @AhmedAbdelhameed thank you this did the trick! – user116922 Jul 08 '19 at 15:53
  • @AhmedAbdelhameed I'm fully aware that this is a question about vbscript, but that is still no reason to start developing without a debugger. There are enough tools out there that can help you develop in VBScript. – Geert Bellekens Jul 09 '19 at 06:16
  • @GeertBellekens mind if you could share the name of the said tools/software? I am a beginner on VB and I would greatly appreciate if I could learn a thing or two. – user116922 Jul 10 '19 at 10:24
  • Vbsedit is one of those tools. I only write scrips for sparx ea, which has its own debugger. – Geert Bellekens Jul 11 '19 at 05:31

0 Answers0