+ Reply to Thread
Results 1 to 10 of 10

Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    49

    Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    I am trying to download a .csv file from a website each day automatically via Task Scheduler, and subsequently do things with that file automatically. It is supposed to run and download a new file each day of the year. I am not sure when the file comes out but it's typically in the late morning.

    Starting to look for the file at 8 AM, Task Scheduler opens/runs a vbs script which opens an Excel workbook automatically, which then downloads the .csv file from a website and formats the data via an Excel module so that it's Access pretty, and then kicks the formatted data into an Access database all automatically. Then it is complete. Rinse and repeat tomorrow.

    If I manually kick start this process in the afternoon (choosing a time after the file actually exists on the website)...it runs flawlessly!

    But if Task Scheduler starts off looking for the file at 8 AM (or any time before the file exists on the website), it downloads a .csv file full of jibberish computer code...not proper data that I seek. Subsequently it tries to format this garbage file and tries to kick it to Access and Access recognizes nothing so Access doesn't accept anything. This is bad.

    My problem is the Task Scheduler THINKS IT WAS SUCCESSFUL...because the process ran...but the file it downloaded although with the correct date in the filename...was a bad, empty file. Therefore the Task Scheduler won't run again until the next day. That is a problem. I need Task Scheduler to keep running every 30 minutes until it gets a good csv file.

    I am not a good programmer. A lot of my code was written by someone else but I can read it and manipulate it.

    Are there ways out there to work around my problem? How can you tell the Task Scheduler that if the data in the file is bunk to retry again in 30 minutes (which is what it's supposed to do)? Or if Access fails to receive data then to run Task Scheduler again in 30 minutes until Access does receive data? Why does the website allow me to download a file that technically isn't ready yet or doesn't exist yet?

    Thank you for any help or suggestions. I hope I explained my problem well. If something doesn't make sense ask me and I will clarify.

  2. #2
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    Task scheduler runs whatever you tell it to run, if it is able to run it then it is a success. It found your excel file and opened it, that's a success.

    If you want to track progress of the file you need to do it on the excel side. You need to do validation on the file after it gets downloaded. This way your code should only close excel if the validation is a success, otherwise it should just restart the process until successful.

  3. #3
    Registered User
    Join Date
    05-26-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    Do you have any suggestions on how to go about doing that?

  4. #4
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    well you can load the csv back in excel and check the first line to see if it's "acceptable" data.

  5. #5
    Registered User
    Join Date
    05-26-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    Like
    If A1 = "" (or empty) Then
    "Task Scheduler not done and needs to rerun until it is done"
    End If

    How do you do the "Task Scheduler not done and needs to rerun until it is done" part?

  6. #6
    Registered User
    Join Date
    05-26-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    I have searched Google back and forth and I can't find much help regarding re-running a successful Task. I guess one of my questions is...at what point in the process does the Task Scheduler say to itself..."I have completed this task successfully?" In my case the Task Scheduler kicks off a vbs script. Is that "successful", merely opening the Excel file which downloads, formats, and moves the file?

    That vbs script opens a Workbook. That Workbook has a "Workbook module" that says what time is it?...if the time is this then run this Main Module. The Main Module downloads the .csv file, opens a formatting module, and sends the formatted file to Access.

    Even though my Task Scheduler says run every 30 minutes until successful it's pointless right now...because whether it's a good or bad csv file...the Task Scheduler thinks it's successful.

    I added in this code into my main module after the .csv file is downloaded. I have no idea if I am on the right path. Thanks for any other suggestions.

    Please Login or Register  to view this content.
    Will Exiting the subroutine and not fully completing everything tell the Task Scheduler that it's not complete...and re-run again in 30 minutes?

  7. #7
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    The easiest way would be to just ask the webmaster of the website when does csv file get created everyday and just sync your task scheduler to that.

    Otherwise if you really want to try and deal with scheduled tasks...

    To create/edit/delete scheduled tasks read this: http://www.howtogeek.com/51236/how-t...-command-line/

    To have excel execute this you read this: http://social.msdn.microsoft.com/For...tside-of-excel

  8. #8
    Registered User
    Join Date
    05-26-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    1) Asking the webmaster when file gets created is not going to happen...and it's random every day.
    2) I already deal with the scheduled task...I just need to be able to kick start the process again if it downloads a bad csv file. You didn't even respond to if my code was on the right path.
    3) I don't really understand what you are suggesting I do. It's too vague for me.

    So hopefully you can help me more specifically, or someone else can help me more specifically, or I will have to pay someone to help me, or I will post to another website and see if people on that website can help me more specifically. Because what I have so far from you isn't helping. But I appreciate you trying. Hopefully someone else can jump on this and help me further.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    What's your code for downloading the file?

  10. #10
    Registered User
    Join Date
    05-26-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Task Scheduler Downloading an Empty, Bad File Before Actual File Exists...Not Good

    Kyle,

    Below is the VBS Script that Task Scheduler Opens starting at some time in the morning looking for the new csv file - Example Task Scheduler starting at 9 AM and the Excel File further below ready to receive the Task at 9 AM.
    Please Login or Register  to view this content.
    When the Workbook Opens it runs this code which resides in the Workbook module...this is DailyDownload.xlsm
    Please Login or Register  to view this content.
    This is the Main Module code that does all of the downloading of the csv file, formatting, and moves it to Access
    Please Login or Register  to view this content.
    Once again, if the file properly exists this runs perfect (outside of that test code in the middle of the main module which I haven't trialed yet). How or where do I restart the Task Scheduler if it downloads a bad csv file? I had to leave some code out to protect the innocent but you have most of it or all the code that matters. If there is any way to private message "special" stuff I can. Thank you.
    Last edited by jamesdeuce; 01-23-2014 at 01:27 PM.

+ 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. Running Excel from task scheduler. Scheduler doesn't end
    By tony h in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2013, 09:49 PM
  2. If txt file exists Then open file in Excel
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2013, 11:15 AM
  3. Download File with VBA and Replace if File Already Exists
    By DAK266 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2012, 02:07 PM
  4. If file exists, run a particular macro, if it doesn't, look for another file
    By tim120harvey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2011, 12:28 PM
  5. Macro to check file exists and take input from the file
    By naidu9295 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-12-2010, 08:15 AM

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