Problems pasting values on another workbook sheet on vba

非 Y 不嫁゛ 提交于 2021-01-28 04:44:23

问题


I have the following code in order to copy a sheet from a workbook and paste it on the sheet 1 of another workbook called "Control_de_precios":

Sub createSpreadSheet()

Set NewBook = Workbooks.Add
With NewBook
    .Title = "Control_precios_ddmmaaaa"
    .Subject = "Control_de_precios"
    .SaveAs Filename:="Control_precios_ddmmaaaa.xls"
End With

ThisWorkbook.Worksheets(1).Activate
Cells.Select
Selection.Copy
NewBook.Sheets(1).Activate
ActiveSheet(1).PasteSpecial xlPasteValues

End Sub

The problem is that I get the 438 error because the last instruction, and I don't get to paste values on my new workbook. If I change it for:

ActiveSheet(1).Paste

I don't get the 438 error, and I get to paste the formulas, but I want to paste the values.

¿Could anyone help me?


回答1:


Add Range reference after the activesheet. When I do it this way it works. ActiveSheet.Range("A1").PasteSpecial xlPasteValues




回答2:


Write

Selection.PasteSpecial xlPasteValues

instaed of

ActiveSheet(1).PasteSpecial xlPasteValues


来源:https://stackoverflow.com/questions/45937731/problems-pasting-values-on-another-workbook-sheet-on-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!