+ Reply to Thread
Results 1 to 5 of 5

Macro - Master file to import data from another open file with variable file name

  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Macro - Master file to import data from another open file with variable file name

    Hi everyone

    Please bear with me, as I am new to macros.

    I have created a spreadsheet (currently just a test/example) that I will send out via email to staff members.
    They will input their information (eg. name, job title, phone number etc) and email it back (so there will be variable file names).
    When I receive the file back from them, I will open that and run a macro from the master spreadsheet that I will copy the information into.

    This is the macro I have so far... (this is just me testing, I haven't fully developed all the content, hence the simplicity)...

    Please Login or Register  to view this content.
    The problem is, when I receive another file and open it eg. "John.xls" (instead of "Jess.xls"), I try to run the macro, it doesn't work because it is a different file name.

    Is there something I can replace in the line:
    Windows("Jess.xls").Activate
    that will allow me to use whatever the other file name is open (whether it be "Jess.xls", "John.xls", "Mary.xls", "Peter.xls" etc etc) and import the data from that file?
    The "master.xls" is the file that contains the macro that will house all the data.

    I have attached the example master file and two test files that people might send to me.

    Master.xlsJess.xlsJohn.xls

    Thanks in advance!

    Jess.
    Last edited by jdodz; 12-07-2012 at 07:00 AM.

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro - Master file to import data from another open file with variable file name

    Hi Jess

    welcome to the forum

    first, can I suggest you put code tags around your code, or a moderator will ping you (most newbies overlook this one!)

    assuming you have only 2 files open, this macro will identify the name of the file other than the active file, and you can use the varialbe name OtherFile in place of the name of the file in your macro:

    Please Login or Register  to view this content.
    your code could be simplified quite a bit by simply specifying the ranges you want to copy from and to - would you like some help with that?

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Macro - Master file to import data from another open file with variable file name

    This macro will copy data from all opened workbooks:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  4. #4
    Registered User
    Join Date
    12-07-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro - Master file to import data from another open file with variable file name

    Hi Nicky and Antonio

    Thanks for the tip re coding tags!

    And thanks to both of you for the coding advice - I will give these a try on Monday and see how they work for me.
    Silly question - where in my code do I paste these?

    Nicky - In regards to the ranges, I'll develop the spreadsheet that the others will fill out a little more and let you know if that's ok? Thanks for the offer, I really appreciate it

    Cheers
    Jess.

  5. #5
    Registered User
    Join Date
    12-07-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Cool Re: Macro - Master file to import data from another open file with variable file name

    Hi Nicky and Antonio

    Thanks once again for your help!

    I used both codes and once I figured out where they went they both worked perfectly.
    I've developed the spreadsheets a bit more and I'll post them on here... I ended up creating a hidden spreadsheet where the data will go to so that the part employees fill out looks good and it is easier to copy the data across to the master.

    Here is what the code looks like:

    Please Login or Register  to view this content.
    Thanks once again!

    Cheers
    Jess.

    Defining Potential - Rob.xlsDefining Potential - Jess.xlsDefining Potential - Master Spreadsheet.xls
    Last edited by jdodz; 12-10-2012 at 10:57 PM. Reason: Forgot to put in code

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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