+ Reply to Thread
Results 1 to 12 of 12

Macro to include date variable SOLVED

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Macro to include date variable SOLVED

    Okay everyone I have a project I am attempting to write a macro for.... Everyday I run a process that creates a file the file name is consistent except for the fact that it adds the date to the end of the file name... So here is my issue I want to write a macro to automatically import the file without the having to pick wich file to import. I want the macro to know to look for the file with todays current date. It will be the only file in the folder I want the macro to grab the file from... I am not sure if this can even be done. Any advice/help would be greatly apprecaited. I have been working on this for a month and have not gotten very far at all. I am extremely new to macros. I am including the template which I want the file imported. As well as the code I have so far.. everytime I try to run the macro I get a runtime error 450.

    The file name will look as such HNBRMT_AGENCY_112812.txt as mentioned before the only thing that changes in the file name is the date at the end. It will always have the current date at the end of the file.
    Please Login or Register  to view this content.

    I hope I have explained this well enough!!
    Attached Files Attached Files
    Last edited by karagill; 11-30-2012 at 10:56 AM. Reason: Solved

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,943

    Re: Macro to include date variable

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    protonLeah,

    Thanks for your reply!! When I tried your code I got the following error

    Compile Error
    Invalid or Unqualified Reference

    Do you have any ideas on why I am getting this error??

  4. #4
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    Okay so I messed with it a little more and it works but it is importing funny its moves my headers in my Template over and imports the data in front of them I need the headers to stay where there at and have it import correctly.. Any ideas on why it is doing this??

  5. #5
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    I need it to import starting at Cell A11

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,943

    Re: Macro to include date variable

    Please post the latest version of your macro. The query.add line looks wrong, you have the file/path twice and you have: Destination:=(A11)
    which should be: Destination:=Range("A1")
    Also, I have some doubts about the parentheses and quotation marks.

  7. #7
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    ProtonLeah,

    Please Login or Register  to view this content.
    I need the import to start at cell A11

    Like I said I am extremely new to macros so I am sure I have a lot of stuff in there that doesnt need to be. I REALLY appreciate your help!!

  8. #8
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    Okay sorry for posting so much but I have cleaned it up a little and I think I am on the right track I think it just needs some slight tweaking I keep getting an error and I am not sure why I get the error Object 438 Doenst support this property or method..

    Please Login or Register  to view this content.
    and when I hit DEBUG this part is highlighted
    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,943

    Re: Macro to include date variable

    Try this one:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    It didnt work I have figured out by playing with the Data Connections that I can get it to automatically import by adding =(TODAY) formula behind the file name. When I ran your code I got an error when I hit debug this part of your code was highlighted.

    Please Login or Register  to view this content.
    I feel like its almost there just missing something small I can't quite figure out what it is??

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,943

    Re: Macro to include date variable

    I noticed a couple of mistakes I left out (red). If that doesn't correct the problem you should post a new question.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to include date variable

    It worked!!!!!!!!!!! I am so excited!! Thanks so much!!!!

+ 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