How to copy file contents from xlsm to another xlsm?

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
Dear All

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

any idea ?

this is my code

VBA 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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Amo,

Use On Error Resume <LabelName> instead of On Error Resume Next.

VBA Code:
Private Sub CommandButton1Click()
On Error GoTo FileIssue
Application.ScreenUpdating = False
Application.DisplayAlerts = False


Dim strPath2 As String
Dim wbk As Workbook

strPath2 = "C:\destination.xlsm"

Set wbk = Workbooks.Open(strPath2)

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

Exit Sub
FileIssue:
MsgBox "Issue in copying content"
End Sub

For Error handling/ Debugging:
Debugging and Error Handling in VBA
 
Upvote 0
Hi,​
just my two cents : for this kind of purpose a good enough VBA procedure does not need any On Error codeline …​
 
Upvote 0
As all well work so this thread is useless ! :rolleyes:
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top