Copy specific data from Workbook A to Workbook B by a button

Pcwork2006

New Member
Joined
Jul 17, 2019
Messages
12
I have set a button to run Marco for the subject action . However, the file name of Workbook A will change every day. I need to correct the file name of Workbook A in Marco before click button. I want to skip the correction step. Please help.
Thank you.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
In the code use ActiveWorkbook instead of the workbook name.
Make sure the correct workbook is activated before running the macro.
 
Upvote 0
In the code use ActiveWorkbook instead of the workbook name.
Make sure the correct workbook is activated before running the macro.

Thank your your reply !
But I dont know how to use ActiveWorkbook code..

Today , my code is:

Windows(“A.xlsx”).Activate
Range(“A3:Q18).Select
Selection.Copy
Windows(“B.xlsm”).Active
Rang(“A4”).Select
ActiveSheet.Paste
 
Upvote 0
Manually activate workbook A then run this :
Code:
Range("A3:Q18").Select
Selection.Copy
Workbooks("B.xlsm").Activate
Range("A4").Select
ActiveSheet.Paste

Which can be reduced to :
Code:
Range("A3:Q18").Copy Workbooks("B.xlsm").Range("A4")
 
Last edited:
Upvote 0
Manually activate workbook A then run this :
Code:
Range("A3:Q18").Select
Selection.Copy
Workbooks("B.xlsm").Activate
Range("A4").Select
ActiveSheet.Paste

Which can be reduced to :
Code:
Range("A3:Q18").Copy Workbooks("B.xlsm").Range("A4")

Ok, I will try this later.
If the button is assigned in workbook B.xslm. This is work or not?
 
Upvote 0
Ok, I will try this later.
If the button is assigned in workbook B.xslm. This is work or not?
No, Because that would mean that Workbook B would be the active workbook when the macro starts.
 
Upvote 0
No, Because that would mean that Workbook B would be the active workbook when the macro starts.
Oh. Then,have you any suggestion on it? Sinece Workbook book is the master data file for consolidate the data from Workbook A (its filename will change,i.e A_201907.xlxs and A_201908.xlxs etc.)
 
Upvote 0
Put a button on each of the workbooks that need to be active before the macro is run (you can still store the macro in Workbook B).
 
Upvote 0
I am not able to add the button in the Workbook A because workbook A is provided by clients every day. Therefore, the file name may has some change ( Workbook A )..
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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