# VBA code not running properly when using Scheduled Tasks



## Rayanea (Aug 19, 2010)

Hello, 

I am not sure this is the right place to post my question but I give it a shot.

I have programmed my computer to turn on at 7am every morning, then using windows' Scheduled Tasks, I am opening an excel workbook at 7:05 am. The workbook is programmed to run a vba code on opening. When I wake up around 7:30 am, I am checking what is happening. I am always surprised to see that the code stops running at one moment (I am retrieving data from the web), and it is not always the same stage. I am 110% sure this is not coming from the VBA code, as when I run it manually (i.e. opening myself the workbook by clicking on it), it works perfectly well.

I am wondering if it does not come from windows or the Scheduled Task software. 

Does someone has any idea from where it could come and how to solve this issue ? 

Thank you very much for your help.


----------



## Rayanea (Aug 20, 2010)

Any clue someone?...


----------



## Derek Brown (Aug 22, 2010)

I don't have the answer as I guess that it would be necessary to look at the code and/or what is being done.
However, the best thing to do is to add some diagnostic code, either as 'debug.print' or details written to a worksheet, and each time you run it you can try to narrow the search down to a section or line of code.


----------



## Norie (Aug 22, 2010)

Is this to do with your other thread?

I don't know if I suggested, but may have, there that problems with this sort of code could be affected by your internet access/connection etc.

Perhaps when you manually run the code something is happening that doesn't happen when it's run using Scheduler.

How exactly are you running the code anyway?

Workbook open event?


----------



## Rayanea (Aug 22, 2010)

Yes, I am using a Workbook open event.

@Norie: indeed, this is the same code as my other thread. But I am not sure there is a problem with the code. 

I thought there was a conflict with other task planned with Scheduled Tasks, but it does not seem to be the case. I will try set the InternetExplorer.Visible to true instead of false to see if it comes from there.

@Derek Brown: how would you insert the debug.print code ? At the end of the loop or every now and then in the code ? 

Thanks for your help.


----------



## Norie (Aug 22, 2010)

I'm not saying the problem is with the code.

I'm trying to say that it could be something to do with your internet connection/speed/access etc

If you are on a network it could be problems with that.


----------



## Derek Brown (Aug 22, 2010)

I would insert something like:

```
.
. ' my code here
.
debug.print "Step 1"
.
. ' my code here
.
debug.print "Step 2"
.
.
```
etc. These would be placed at important parts of the code, within loops if there is code there that is doing something relevant. If within a loop it would be better to include a 'counter' e.g.

```
debug.print "Step 5 (" & lngKounter & ")"
lngKounter = lngKounter + 1
```
In the VBE 'Immediate' window you would see Step 1, Step 2 etc. and then know how far it gets each time.


----------



## Rayanea (Aug 23, 2010)

I tried this morning with the InternetExplorer.Visible = True

When I woke up, I noticed that the program was running, but nothing was progressing (as usual I would say). Interestingly, no IE window was open, and the processor was 100% used. However, I still noticed a iexplorer process in the Windows Task Manager. I am really wondering if there is no conflict with the Google updates scheduled in Task Scheduler. 

I guess there is a conflict somewhere, but can't figure out where... I am trying with the debug.print tonight.

Note that I am not on a network.


----------



## Rayanea (Aug 26, 2010)

Hello, 

I think I could have figured out where the  problem lies and apparently it could have nothing to do with the Task Scheduler.

After having updated my code, I ran it and watched it opening and closing IE windows as it does normally.

On one particular window, the page couldn't load properly. I waited some time but nothing happened. Then I tried a refresh with F5. The page reloaded properly and the code continued to run.

Hence, I am wondering if I should not use the Refresh method for IE application in case the page is still not loaded after a certain amount of time ? 

Thank you very much for your feedback.


----------

