简体   繁体   English

如何将文件内容从 xlsm 复制到另一个 xlsm?

[英]How to copy file contents from xlsm to another xlsm?

I want to transfer data from the master workbook to another workbook If the transfer to destination.xlsx is successful but if transfer to destination.xlsm is unsuccessful我想将数据从主工作簿传输到另一个工作簿如果传输到destination.xlsx 成功但如果传输到destination.xlsm 不成功

this is my code这是我的代码

Private Sub CommandButton1_Click()

Dim strPath2 As String
Dim wbk As Workbook

strPath2 = "C:\destination.xlsm"

On Error Resume Next

Set wbk = Workbooks.Open(strPath2)


Application.ScreenUpdating = False
Application.DisplayAlerts = False

 
ThisWorkbook.Worksheets("Master").Range("A1:A30").Copy
wbk.Worksheets("destination").[E15].PasteSpecial Paste:=xlPasteValues
    
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

You entire code work properly, except this part,除了这部分之外,您的整个代码都可以正常工作,

ThisWorkbook.Worksheets("Master").Range("A1:A30").Copy
wbk.Worksheets("destination").[E15].PasteSpecial Paste:=xlPasteValues

By using copy method, you can input destination subsequent without the need for paste special:通过使用复制方法,您可以在后续输入目的地,而无需特殊粘贴:

Sheet1.Range("A1:A5").Copy wbk.Worksheets("Sheet1").Range("A1")

Eventually it perform same step as your need with less code.最终,它使用更少的代码执行与您需要相同的步骤。

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

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