+ Reply to Thread
Results 1 to 6 of 6

Search for Filename with Date and Open File

  1. #1
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    Search for Filename with Date and Open File

    Example: Today's date is 28 November 2011

    I have a folder "C:\2011\" which contains xlsx files. For this example, lets say there are 5 files:
    Record_28 Jan.xlsx
    Record_04 Feb.xlsx
    Record_15 Apr.xlsx
    Record_22 Jun.xlsx
    Record_13 Aug.xlsx

    I need a macro that scans in folder "C:\2011\" and opens the file with the closest date.

    I have written the following, but it couldn't work. Can someone please help me check what went wrong with this code?
    Please Login or Register  to view this content.
    Additional Details:
    I am getting an error message
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Run-time error '91':
    Object variable or With block variable not set
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    The code stops at the line after 'While VCont'
    Last edited by Gingeiko; 11-29-2011 at 08:01 PM.

  2. #2
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Search for Filename with Date and Open File

    Ok I tried another alternative:

    Please Login or Register  to view this content.
    For this I'm getting an error Overflow
    and the line i = i + 1 is highlighted. Any ideas???
    Last edited by Gingeiko; 11-28-2011 at 03:22 AM.

  3. #3
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Search for Filename with Date and Open File

    Ok...I was being really careless....I missed the ".xlsx" in searching for file.

    The code is now working:
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    11-04-2011
    Location
    pak
    MS-Off Ver
    Excel 2007
    Posts
    132

    Re: Search for Filename with Date and Open File

    great i was doing this code,but stuck too. thanks for sharing

  5. #5
    Registered User
    Join Date
    06-26-2011
    Location
    sri lanka
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search for Filename with Date and Open File

    hi can you please explain how do i this

  6. #6
    Registered User
    Join Date
    11-28-2011
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Search for Filename with Date and Open File

    Quote Originally Posted by rizviy View Post
    hi can you please explain how do i this
    Example:
    If you have 3 files in your folder, lets say "C:\My Folder\". And the files are:
    "My File_03 Apr.xlsx"
    "My File_25 Nov.xlsx"
    "My File_13 OCt.xlsx"

    Then this code should find the file with latest date, which is "My File_25 Nov.xlsx", and open it.

    For that to work, replace the following variable with information from this example, in the code below:
    Your_Fold_To_Look_For_File = My Folder
    Your_File_Fixed_Name = My File_

    Please Login or Register  to view this content.
    Last edited by Gingeiko; 11-29-2011 at 08:17 PM.

+ 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