+ Reply to Thread
Results 1 to 11 of 11

Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    Chapel Hill, NC
    MS-Off Ver
    Excel 2007/2010/2013
    Posts
    10

    Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    I have a come across a fantastic macro that allows users to download a great amount of stock market data. It is the first of its kind that I have come across, and I can foresee a lot of uses for it.

    It can be downloaded here: http://investexcel.net/download-finviz-data/

    Unfortunately, in order to build a database from this macro, it needs to be updated and saved each day, as it does not specify any kind of date ranges to pull the data from. In order to build an effective database without automation, one would have open Excel manually, run the macro, and save the finally manually with the current date.

    Can anyone provide guidance for solving this problem? I believe I can use Task Scheduler in Windows 7 to open Excel automatically after 4:30 pm EST each weekday (has to be after the close of the stock market), but I still need to find a way to:

    1) Run the Macro automatically to update the data after Excel opens automatically with Task Scheduler
    2) Automatically do a Save As that saves the new file into a specified folder with the date it was downloaded in the title

    Ideally, it would be fantastic if someone could figure out how to task on the a third step where,

    3) The data tab from each separately downloaded file could then be added back into a Master Workbook with each tab labeled with it's respective date of data extraction

    Can anyone provide guidance on how to go about setting up this system? I will be extremely appreciative! Thank you so much.
    Last edited by bkanne; 05-13-2014 at 05:39 PM.

  2. #2
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    You are on the right track. Use task scheduler to open excel at a given time. Create a new workbook and save it under.

    C:\Users\....\AppData\Roaming\Microsoft\Excel\XLSTART

    So that when excel opens it will open that file at that given time. Put your code in this workbook and use this and put your code in between

    Please Login or Register  to view this content.
    Thank those who have helped you by clicking the Star * below their name and please mark your post [SOLVED] if it has been answered satisfactorily.

  3. #3
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Did this work for you?

  4. #4
    Registered User
    Join Date
    08-09-2012
    Location
    Chapel Hill, NC
    MS-Off Ver
    Excel 2007/2010/2013
    Posts
    10

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Jesse,

    Thanks so much for responding and staying on top of this. I added your additional code to my workbook and set up Excel to open using the Task Scheduler. Getting the file to open in Task Scheduler works fine, but I get an error when trying to add your code to my mine to run the macro. This is what my code looks like:

    Please Login or Register  to view this content.

    The error says: Compile error: Expected End Sub.
    I am an amateur with VB, but I tried rearranging the code several times and didn't really get anywhere. Just an FYI, the code I am using already had an "End Sub" at the end.... I am not sure if there is a conflict with trying to add an additional "EndSub" as you directed in your reply. Any additional guidance would be greatly appreciated!

  5. #5
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Take out the double sub at the top

    Please Login or Register  to view this content.
    Sub is the begining and end sub is the end. If you have two subs then it thinks you have two beginings.

  6. #6
    Registered User
    Join Date
    08-09-2012
    Location
    Chapel Hill, NC
    MS-Off Ver
    Excel 2007/2010/2013
    Posts
    10

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Thanks. The Macro runs now without an error, but it doesn't run automatically after Task Scheduler opens the file. I still have to run it manually. Am I missing something?

  7. #7
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Did you save the macro to a workbook in VBA under tab "this workbook" and put it in this location "C:\Users\....\AppData\Roaming\Microsoft\Excel\XLSTART"? If not excel will not open the file with the macro in it. The macro is correct if you have taken out the sub getfinvizdata and left the Private Sub Workbook_Open() it should open and run the macro when the task manager opens excel at the time you setup.

  8. #8
    Registered User
    Join Date
    08-09-2012
    Location
    Chapel Hill, NC
    MS-Off Ver
    Excel 2007/2010/2013
    Posts
    10

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    It seems to be working now, thank you. Now all I need to figure out how to do is automatically have the file "Save As" with the current date after the data downloads.

  9. #9
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Make sure to put your directory before where the C:/ is in the code otherwise it won't save anywhere and it will give you an error.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-09-2012
    Location
    Chapel Hill, NC
    MS-Off Ver
    Excel 2007/2010/2013
    Posts
    10

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Works fantastically, with one exception. I had to change the Date formatting during the Save As from "mm/dd/yy" as you had listed to "mm-dd-yy" because the slash was being read as part of the destination directory and causing an error.

    The final code looks like this:

    Please Login or Register  to view this content.
    I also had to add the "Application.DisplayAlerts = False" to get a warning box to stop popping up each time the macro ran. Thanks so much.

  11. #11
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Automatically Start Excel, Run Macro, and Save-As Each Day at a Specified Time

    Awesome. I am glad it worked for you. Great job putting on the final touches. Thank you for the rep. Don't forget to mark your thread as solved please.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 02-15-2012, 01:04 PM
  2. Macro to save certain sheets from excel automatically
    By Libster78 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2010, 05:13 AM
  3. display end time automatically upon entering start time and time usage
    By stoey in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-19-2008, 06:16 PM
  4. Automatically Save an excel file at a certain time
    By RobbieBobbie23 in forum Excel General
    Replies: 2
    Last Post: 06-26-2007, 02:16 PM
  5. Help! My macro won't automatically start when I open Excel.
    By john928 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2005, 06:55 AM

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