How do I create a macro that copies data from one excel file to another and saves it as a new name?

%3CLINGO-SUB%20id%3D%22lingo-sub-2606545%22%20slang%3D%22en-US%22%3EHow%20do%20I%20create%20a%20macro%20that%20copies%20data%20from%20one%20excel%20file%20to%20another%20and%20saves%20it%20as%20a%20new%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2606545%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20file%20called%20%22!PaymentTemplate.xlsx%22%20and%20I%20have%20a%20folder%20called%20%22Output%22%20that%20contains%20many%20files.%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20create%20a%20macro%20that%20opens%20up%20the%20%22!PaymentTemplate.xlsx%22%20file%2C%20then%20opens%20up%20one%20file%20from%20the%20%22Output%22%20folder%2C%20copies%20and%20pastes%20the%20data%20from%20that%20second%20file%20into%20the%20Template%20file%20and%20then%20saves%20it%20as%20a%20new%20name.%20I%20would%20like%20this%20process%20repeated%20for%20each%20of%20the%20unique%20files%20in%20the%20Output%20folder.%20I%20do%20not%20want%20the%20data%20appended%20together%2C%20each%20unique%20file%20gets%20pasted%20in%20the%20blank%20Template%20file.%20So%20if%20I%20have%2010%20files%20in%20the%20Output%20folder%2C%20I%20would%20have%2010%20new%20saved%20files.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAttached%20is%20an%20example%20of%20two%20files%2C%20MP2%20and%20Sunrise%20each%20resulting%20in%20a%20new%20file%20MP2_New%20and%20Sunrise_New.%20The%20Template%20file%20was%20opened%20for%20each%20one%20separately%2C%20data%20pasted%20in%2C%20and%20then%20resaved.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20not%20trying%20to%20do%20anything%20fancy%2C%20more%20just%20automate%20copying%20and%20pasted%20many%20files.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20help%20and%20guidance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2606545%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2606689%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20create%20a%20macro%20that%20copies%20data%20from%20one%20excel%20file%20to%20another%20and%20saves%20it%20as%20a%20new%20na%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2606689%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1119636%22%20target%3D%22_blank%22%3E%40Shmelky%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20admit%20to%20a%20bias%20against%20macros%2C%20so%20take%20what%20I%20say%20with%20a%20grain%20(or%20lump%2C%20as%20you%20see%20fit)%20of%20salt.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20you're%20describing%20may%20be%20totally%20unnecessary%2C%20and%20certainly%20could%20be%20a%20failure%20to%20take%20advantage%20of%20Excel's%20ability%20to%20manipulate%20data%20via%20some%20of%20its%20many%20functions.%20Using%20a%20macro%20to%20copy%20and%20paste%20(when%20in%20fact%20Excel%20could%20simply%20retrieve%20the%20data%20into%20that%20template)%20is%20using%20what%20I'd%20call%20a%20%22brute%20force%22%20method%20instead%20of%20taking%20advantage%20of%20the%20elegance%20of%20the%20software.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20you%20say%20you're%20not%20interested%20in%20%22anything%20fancy%2C%22%20I'll%20leave%20it%20at%20that.%20If%20it's%20possible%20you'd%20be%20open%20to%20some%20alternative%20solutions%2C%20let%20us%20know.%20Or%20perhaps%20somebody%20else%20without%20my%20bias%20against%20macros%20will%20write%20that%20macro%20for%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I have a file called "!PaymentTemplate.xlsx" and I have a folder called "Output" that contains many files.

I am trying to create a macro that opens up the "!PaymentTemplate.xlsx" file, then opens up one file from the "Output" folder, copies and pastes the data from that second file into the Template file and then saves it as a new name. I would like this process repeated for each of the unique files in the Output folder. I do not want the data appended together, each unique file gets pasted in the blank Template file. So if I have 10 files in the Output folder, I would have 10 new saved files.

 

Attached is an example of two files, MP2 and Sunrise each resulting in a new file MP2_New and Sunrise_New. The Template file was opened for each one separately, data pasted in, and then resaved.

 

I am not trying to do anything fancy, more just automate copying and pasted many files.

 

Thank you for your help and guidance.

2 Replies

@Shmelky 

 

I will admit to a bias against macros, so take what I say with a grain (or lump, as you see fit) of salt.

 

What you're describing may be totally unnecessary, and certainly could be a failure to take advantage of Excel's ability to manipulate data via some of its many functions. Using a macro to copy and paste (when in fact Excel could simply retrieve the data into that template) is using what I'd call a "brute force" method instead of taking advantage of the elegance of the software.

 

Since you say you're not interested in "anything fancy," I'll leave it at that. If it's possible you'd be open to some alternative solutions, let us know. Or perhaps somebody else without my bias against macros will write that macro for you.

I totally agree and I actually had all this done in Knime... BUT.... The reason why I am going the Macro route is because I upload data to a site where I need to use their Template file. It is protected in such a way that I can paste data in , but the site knows when I use that file versus another identical file. That is why I need to open the Template file, and paste data into it, and then resave it as a new name.