1
votes

I have code in one workbook, this should open another workbook, copy and paste into the workbook with the code. I can select the data but can't paste it.

I have tried many different variations of code getting errors or it doesn't do anything. An example is run in template.xls, which is where I want to paste the data:

Set dlsheet = appexcel.Workbooks.Open(strPath & "downloadedData.xls")

With dlsheet.Sheets("Data")

    .range("A1:H3").Select.copy
    selection.copy

End With

I don't know how to use the selection since this will copy from the template, I tried using a full stop before selection.

I can copy the entire sheet from dlsheet into a new workbook, if someone could tell me how to copy it to the template and not a new workbook then this would also do the trick.

dlsheet.Sheets("Data").Copy
2
To Copy you can directly use this .Range("A1:H3").Copy instead of .range("A1:H3").Select.copySiddharth Rout
Ah sorry I din't mean for that copy to be after the select (.range("A1:H3).Select) is what I meant to enterTBone2087
I have one suggestion, if you are copying entire document from the template then do not use copy and paste method. I think there is Open method which will accept the template document file name as parameter. If you call that method it will automatically copy your template document contents to new document.Sudhakar B
If you are creating a copy from the template then do as @Sudhakar suggested. As mentioned in my previous comment if you use .Range("A1:H3").Copy then you don't need the next line which is selection.copy :)Siddharth Rout
Thanks, that worked. I now have another problem which I had before and haven't been able to solve.TBone2087

2 Answers

1
votes
Set dlsheet = appexcel.Workbooks.Open(strPath & "downloadedData.xls")
dlsheet.Sheets("Data").range("A1:H3").copy

ThisWorkbook.ActiveSheet.Paste Destination:=ThisWorkbook.ActiveSheet.Range( "A1:H3")
0
votes

Try this

Set dlsheet = appexcel.Workbooks.Open(strPath & "downloadedData.xls")

With dlsheet
    .Sheets("Data").Range("A1:H3").Copy

    .Sheets("Data").Range("A1").PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With