+ Reply to Thread
Results 1 to 5 of 5

Open an Excel file with a date as today in a macro

  1. #1
    Perry
    Guest

    Open an Excel file with a date as today in a macro

    Hello,

    I'm creating a daily report with certain data.

    One of the steps to create this report is the input of certain data
    from one Excel file into another. The destination file for this data is
    an Excel file which always has a name as follows:

    ---> Daily_Report_Perry_dd-mm-yyyy.xls

    How do I create a macro which always opens the file above with the
    "today" date? By example today, wednesday the 9th of November, the
    following file should be opened:

    ---> Daily_Report_Perry_09-11-2005.xls


  2. #2
    Bernie Deitrick
    Guest

    Re: Open an Excel file with a date as today in a macro

    Perry,

    When you use the file name, create it using the Format function:

    Dim myFileName As String
    myFileName = "Daily_Report_Perry_" & Format(Now, "dd-mm-yyyy") & ".xls"
    MsgBox myFileName

    Then use the variable myFileName wherever you were using the name string.

    HTH,
    Bernie
    MS Excel MVP


    "Perry" <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > I'm creating a daily report with certain data.
    >
    > One of the steps to create this report is the input of certain data
    > from one Excel file into another. The destination file for this data is
    > an Excel file which always has a name as follows:
    >
    > ---> Daily_Report_Perry_dd-mm-yyyy.xls
    >
    > How do I create a macro which always opens the file above with the
    > "today" date? By example today, wednesday the 9th of November, the
    > following file should be opened:
    >
    > ---> Daily_Report_Perry_09-11-2005.xls
    >




  3. #3
    Bernie Deitrick
    Guest

    Re: Open an Excel file with a date as today in a macro

    Perry,

    I guess I should have included how to open the file:

    Dim myFileName As String
    myFileName = "Daily_Report_Perry_" & Format(Now, "dd-mm-yyyy") & ".xls"
    Workbooks.Open "C:\Foldername\" & myFileName

    HTH,
    Bernie
    MS Excel MVP


    "Bernie Deitrick" <deitbe @ consumer dot org> wrote in message
    news:[email protected]...
    > Perry,
    >
    > When you use the file name, create it using the Format function:
    >
    > Dim myFileName As String
    > myFileName = "Daily_Report_Perry_" & Format(Now, "dd-mm-yyyy") & ".xls"
    > MsgBox myFileName
    >
    > Then use the variable myFileName wherever you were using the name string.
    >
    > HTH,
    > Bernie
    > MS Excel MVP
    >
    >
    > "Perry" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hello,
    >>
    >> I'm creating a daily report with certain data.
    >>
    >> One of the steps to create this report is the input of certain data
    >> from one Excel file into another. The destination file for this data is
    >> an Excel file which always has a name as follows:
    >>
    >> ---> Daily_Report_Perry_dd-mm-yyyy.xls
    >>
    >> How do I create a macro which always opens the file above with the
    >> "today" date? By example today, wednesday the 9th of November, the
    >> following file should be opened:
    >>
    >> ---> Daily_Report_Perry_09-11-2005.xls
    >>

    >
    >




  4. #4
    bpeltzer
    Guest

    RE: Open an Excel file with a date as today in a macro

    Your open statement would be something like
    Workbooks.Open Filename:="c:\temp\" & Format(Date, "mm-dd-yyyy") & ".xls"


    "Perry" wrote:

    > Hello,
    >
    > I'm creating a daily report with certain data.
    >
    > One of the steps to create this report is the input of certain data
    > from one Excel file into another. The destination file for this data is
    > an Excel file which always has a name as follows:
    >
    > ---> Daily_Report_Perry_dd-mm-yyyy.xls
    >
    > How do I create a macro which always opens the file above with the
    > "today" date? By example today, wednesday the 9th of November, the
    > following file should be opened:
    >
    > ---> Daily_Report_Perry_09-11-2005.xls
    >
    >


  5. #5
    Perry
    Guest

    Re: Open an Excel file with a date as today in a macro

    Bernie,

    Thank you! It works perfectly.

    I'd already tried the "&Format(Now, "dd-mm-yyyy") & ".xls" function but
    somehow it didn't work. Now it does!

    I think it had to do with Dim myFileName As String.

    Perry


+ 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