+ Reply to Thread
Results 1 to 4 of 4

VBA - Saving different files from a template and raw separated data

  1. #1
    Registered User
    Join Date
    09-15-2019
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    5

    VBA - Saving different files from a template and raw separated data

    I have a template file at its own folder where I copy data into from a bunch of perodic files from a different directory. The process I am attempting to automate is to copy data from first periodic file into the template, save the resulting feeded template naming it as the first data source file ("1" in the example) and then go back to the original empty template in order to loop the process with the rest of periodic files.

    My clumsy attempt to this point has been the following:

    I first copy data from "1" to "template":

    Workbooks.Open fileName:= _
    "C:\sample\template\template.xlsx"
    Workbooks.Open fileName:= _
    "C:\sample\1.xlsx"

    Windows("1.xlsx").Activate
    Range("A2").Select
    Selection.Copy
    Windows("template.xlsx").Activate
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Then I want to save "template" with the added data as "1.xlsx" but into the template folder:

    Windows("1.xlsx").Activate
    [[ActiveWorkbook.Name.Copy]]?????
    Windows("template.xlsx").Activate
    [[Saveas.Paste & ".xlsx"]]?????

    Since I have no basic knowledge in programming but recording and cleaning up a couple of macro lines, I am really stucked into the "copy filename and save as pasting" steps. I assume there is a more efficient approach to the whole process but by now I just want to make the second part work if possible.

    If you think I really need some basis before attempting stuff like that just give me the keywords to adress my learning.

    Thanks in advance
    Last edited by JordiDash; 10-19-2019 at 01:50 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,443

    Re: VBA - Saving different files from a template and raw separated data

    Some suggestions you may find useful:
    1. Our answerers are looking to "help" more often than they are looking to "do an entire project for you for free".
    2. Jump into this project yourself, when you get stuck on ONE specific hurdle, post that ONE item as a forum question.
    3. Show us what you've tried in an attached sample workbook and how it's not working for you. When you're doing the work yourself, just writing out a complete example question in a forum often points you to solution before you even finish posting.
    4. If you can't make any headway at all and no help is forthcoming in the free forum(s), we do have a Commercial Services forum where you can pay for assistance directly from our EF gurus."

  3. #3
    Registered User
    Join Date
    09-15-2019
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA - Saving different files from a template and raw separated data

    After discovering Name As and FileCopy I got the whole loop working for all files in the same directory:

    Please Login or Register  to view this content.

    Any suggestion to polish this procedure?
    Last edited by Pepe Le Mokko; 10-20-2019 at 02:57 AM.

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,443

    Re: VBA - Saving different files from a template and raw separated data

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I did it for you this time. Please read forum rules. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 11-13-2017, 01:36 AM
  2. [SOLVED] Export Data in Rows, Separated by Empty Cells to Text Files
    By leoxanigm in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-16-2014, 09:53 AM
  3. Saving Data from Excel Template
    By guardsman in forum Excel General
    Replies: 0
    Last Post: 09-30-2013, 07:47 AM
  4. CSV file created from template is not saving to same location as the template.
    By SGALLAG1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2012, 11:26 AM
  5. Replies: 0
    Last Post: 02-28-2012, 11:40 AM
  6. Saving Comma Separated .txt files as .csv files
    By twills in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-15-2009, 06:03 PM
  7. Replies: 2
    Last Post: 06-12-2006, 12:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1