简体   繁体   中英

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

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.

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