简体   繁体   中英

Paste Special in VBA

I am looking to paste values for the following piece of code. I tried using paste special a variety of ways but it does not let me specify both the file and what type of pasting I want to do.

To be clear, the code I am using works, but I would like to modify it so it pastes only values.

Workbooks.Open (path & file)
ActiveSheet.Paste (Workbooks(file).Sheets(5).Range("A1").End(xlDown).Offset(1, 0))
Workbooks(file).Close SaveChanges:=True 

Thank you!

Instead of using the PasteSpecial associated with a worksheet object, use the one associated with the destination object:

Workbooks(file).Sheets(5).Range("A1").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValues

OR

You can work directly with the values and avoid using the clipboard (which you could be trying to use for other things while your macro is running):

Dim src as Range
Dim dest as Range

'Set src to where you had copied from
Set dest = Workbooks(file).Sheets(5).Range("A1").End(xlDown).Offset(1, 0)
dest.value = src.value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM