简体   繁体   English

VBA Excel中将值从一个工作簿复制到另一个?

[英]vba excel copy values from one workbook to another?

I am trying to copy my values from when workbook to another workbook and paste the values starting from row 200 on the target workbook. 我试图将值从工作簿复制到另一个工作簿,并将值从第200行开始粘贴到目标工作簿上。

I am new to vba so just been trying to use the following code to do what I need to do but it won't work, ideally I want the copy and paste to take place without the target workbook being opened. 我是vba的新手,所以一直试图使用以下代码来完成我需要做的事情,但是它无法正常工作,理想情况下,我希望在不打开目标工作簿的情况下进行复制和粘贴。

Can someone please show me how I can get my code to do what I need? 有人可以告诉我如何使我的代码执行我需要的工作吗? Thanks in advance, 提前致谢,

Dim ws10 As Worksheet, ws12 As Worksheet
Dim DestRow As Long
Set ws10 = Workbooks("\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\Supplier SetUps & Amendments.xls").Sheets("Statistics")
Set ws12 = Workbooks("\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\Supplier Tracking & Management.xls").Sheets("SupplierTracking")
DestRow = ws12.Cells(Rows.Count, "B").End(xlUp).Row + 1
ws10.Range("A" & ActiveCell.Row).Copy
ws12.Range("B" & DestRow).PasteSpecial xlPasteValuesAndNumberFormats 

To turn the destination workbook not visible i recommend you to create another object to open it. 若要使目标工作簿不可见,我建议您创建另一个对象以将其打开。 But you can't PasteSpecial in another object so you need to just paste it. 但是您不能将PasteSpecial粘贴到另一个对象中,因此只需要粘贴它即可。

Dim ws10 As Worksheet, ws12 As Worksheet
Dim DestRow As Long
Dim objExcel
Dim objWkb

Set objExcel = CreateObject("Excel.Application")
Set objWkb = objExcel.Workbooks.Open("\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\Supplier Tracking & Management.xls")

Set ws10 = Workbooks("\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\Supplier SetUps & Amendments.xls").Sheets("Statistics")
Set ws12 = objWkb.Sheets("SupplierTracking")
DestRow = ws12.Cells(Rows.Count, "B").End(xlUp).Row + 1
ws10.Range("A" & ActiveCell.Row).Copy
ws12.Range("B" & DestRow).Paste

Don't forget to save and quit the workbook before the end of your code. 不要忘记在代码结束之前保存并退出工作簿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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