1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Auto updating Date in Macro

Discussion in 'Business Applications' started by JackAndCoke, Jun 12, 2007.

Thread Status:
Not open for further replies.
  1. JackAndCoke

    JackAndCoke Thread Starter

    Joined:
    Apr 26, 2007
    Messages:
    152
    I have this macro that I run for my report and it goes and opens other excel files and pulls information from them. The excel files have the same names except everyday i have to change the macro to get the same file name with a variance in the date as shown below.


    Code:
    Sub Update_Dashboard()
        Sheets("Lampe").Visible = True
        Sheets("Kay").Visible = True
        Sheets("Magoulas").Visible = True
        Range("C5").Select
        Application.Run "'2007-05 June- EXPO Task Trends Dashboard [COLOR="Red"]0612[/COLOR].xls'!Erase_Data"
        Application.Run "'2007-05 June- EXPO Task Trends Dashboard [COLOR="red"]0612[/COLOR].xls'!Magoulas"
        Application.CutCopyMode = False
        Application.Run "'2007-05 June- EXPO Task Trends Dashboard [COLOR="red"]0612[/COLOR].xls'!Kay"
        Application.CutCopyMode = False
        Application.Run "'2007-05 June- EXPO Task Trends Dashboard[COLOR="red"] 0612[/COLOR].xls'!Lampe"
        Range("C45").Select
        Application.CutCopyMode = False
        Application.Run _
            "'2007-05 June- EXPO Task Trends Dashboard [COLOR="red"]0612[/COLOR].xls'!Atlanta_CSC"
        Range("C46").Select
        Application.CutCopyMode = False
        Application.Run "'2007-05 June- EXPO Task Trends Dashboard [COLOR="red"]0612[/COLOR].xls'!OC_CSC"
        Range("A2").Select
        Sheets("Lampe").Visible = False
        Sheets("Kay").Visible = False
        Sheets("Magoulas").Visible = False
    End Sub
    The numbers in red always represent MMDD of the current date. Is there anyway to have VBA change those numbers everyday so that I don't have to change my macro everyday? I know with python you can use 'string' +function + 'string' and I was hoping you could do the same thing with VBA. Any help is greatly appreciated.
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Try something like

    Code:
    Application.Run "'2007-05 June- EXPO Task Trends Dashboard " & Format(Now, "MM") & Format(Now, "DD") & ".xls'!Erase_Data"
    Regards,
    Rollin
     
  3. JackAndCoke

    JackAndCoke Thread Starter

    Joined:
    Apr 26, 2007
    Messages:
    152
    Perfect! Thanks!
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/583461

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice