+ Reply to Thread
Results 1 to 5 of 5

Extracting data from file in directory and extracting filename

  1. #1
    Registered User
    Join Date
    09-30-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    85

    Extracting data from file in directory and extracting filename

    Hi all,

    I have a directory folder with an active workbook and another workbook id like to copy data from. The Following macro opens up a file in the same directory, copies some data and pastes it in the active workbook. However with this code I have to specify the filename, 'Data.xlsm' in the example code. I would like it to copy data from the only other workbook in the current directory WITHOUT having to specify the name in the code, so just opening it up no matter what filename it has.

    In addition I would like to extract the filename from the workbook im copying data from and paste it into the activewoorkbook in sheet 1 Cell A1. I had a look at getopenfilename function but cant seem to make it work for my purpose.

    Thanks very much!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extracting data from file in directory and extracting filename

    Do you mean like this?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-30-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Extracting data from file in directory and extracting filename

    Yes jindin! Thank you, however just a couple things... I would like the data to be pasted as values rather than just a normal paste.

    Also after selecting the file to copy data from, it seems to take about 20 seconds to complete, whereas the code I posted takes about 5. Any idea why this is, and if it can be quicker?

    Thanks!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extracting data from file in directory and extracting filename

    The difference between yours and mine is only:
    Please Login or Register  to view this content.
    So it should not make any difference in execution time....

    If you want to copy values then change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-30-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Extracting data from file in directory and extracting filename

    Excellent! Ah yeah it turns out pasting as values is much quicker! Thanks very much jindon

+ 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. Extracting Directory list contents
    By mvalenc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-15-2012, 06:24 AM
  2. Extracting the folder name and filename from a file path?
    By Skywalker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 08:17 PM
  3. Replies: 3
    Last Post: 06-11-2009, 07:08 PM
  4. [SOLVED] Extracting data from directory listing
    By DK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2006, 07:50 PM
  5. [SOLVED] Extracting filename
    By Nigel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-23-2005, 03:06 PM

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