+ Reply to Thread
Results 1 to 6 of 6

use a macro to Open a file with a variable filename

  1. #1
    Registered User
    Join Date
    05-24-2010
    Location
    lONDON
    MS-Off Ver
    Excel 2007
    Posts
    7

    use a macro to Open a file with a variable filename

    Hi,

    I'm pretty new to Macros and VB and I am trying to run a marco that opens a file.

    The file name however changes on a daily basis

    "Open Position Client Count (Daily)2010-05-24-01-35-27.xls"

    I can open the file if the filename contained only the date however I'm stuck with the issue of time, the time is diferent every day.

    I have tried to use

    Workbooks.Open Filename:= _
    "T:\crystal_reports\General\Oracle_Web_Trading_Reports\"Open Position Client Count (Daily)" & Format(Date, "yyyy-mm-dd-HH-MM-SS") & ".xls

    But that looks for a file called "Open Position Client Count (Daily)2010-05-24-00-00-00.xls"

    Any ideas?

    Thanks

    Ben
    Last edited by plunkettyplunk; 06-11-2010 at 04:06 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: use a macro to Open a file with a variable filename

    Here's one way to do it:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-24-2010
    Location
    lONDON
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: use a macro to Open a file with a variable filename

    Hey, apologies for not replying before now, but that worked a treat. thanks for your help.

    Take it easy

    Ben

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: use a macro to Open a file with a variable filename

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Registered User
    Join Date
    07-04-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010, 2007
    Posts
    13

    Re: use a macro to Open a file with a variable filename

    Hi,

    I have a similar issue, but thing is that i need excel file from intranet webpage which contains bulk of excel files, (always file name contains date in it) example= position report 20130706, on daily basis i want previous days data to be extracted. can i make use of above coding.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: use a macro to Open a file with a variable filename

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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