不使用剪贴板粘贴特殊内容 [英] Paste special without using clipboard

查看:76
本文介绍了不使用剪贴板粘贴特殊内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一系列数据从一个文件粘贴到另一个文件.但这会影响目标文件的格式.请求您的帮助.

I am trying to paste a range of data from one file to another. but this is affecting the format of the destination file. Request your help.

下面是我正在使用的代码的一部分:

Below is a part of the code that I am using:

    Dim repdata As Range

    Set wb1 = Workbooks.Open("file name")

    Set repdata = Range("A2", Cells(lastrow, lastcol))

    Set wb = Workbooks.Open("file2")

    repdata.Copy Destination:=Range("B8")

但这会覆盖目标中的格式.

But this is overwriting the format in the destination.

我尝试过:

    repdata.Copy Destination:=Range("B8").PasteSpecial(xlPasteValues).

这不起作用.给出错误

我也尝试过

    repdata.Copy Destination:=Range("B8").PasteSpecial xlPasteValues. 

即使这不起作用.给出错误

Even this is not working. Its giving error

推荐答案

很难给您一个确定的答案,因为您没有使用

It's hard to give you a definitive answer, because you didn't post your question with a Minimal, Complete and Verifiable Example - should be something you should keep in mind in future questions.

要回答您的问题,斧头很可能就在这里-请勿将目标 PasteSpecial
一起使用假设代码中的所有其他功能都正常,这应该可以正常工作.

To answer your question, the axe most likely lies here - Don't use Destination with PasteSpecial
This should work fine, presuming everything else in your code is functional.

Dim repdata As Range
Dim wb1 as Workbook, wb2 As Workbook

Set wb1 = Workbooks.Open("file name")
Set wb2 = Workbooks.Open("file2")
Set repdata = wb1.Range("A2", Cells(lastrow, lastcol))

repdata.Copy
wb2.Range("B8").PasteSpecial xlPasteValues

这篇关于不使用剪贴板粘贴特殊内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆