Log in

View Full Version : Help with VBA timin issue on task scheduler



gripper
09-15-2014, 12:20 AM
Hi,
I have obtained this VBA from the forum and have tried to changed it for my needs but whatever I do doesn't seem to work.

Can anyone out there see where I have gone wrong. When Task scheduler runs, I want it to run 3 macros if the time is before 6.30am but only run 2 after that. It will open the Excel file at 6am, but nothing seems to happen as the excel report remains open unti I arrive into work.



Private Sub TestInteractive()
Application.DisplayAlerts = False
If GetActiveWindow() = 0 Then
' We're running via the Task Scheduler: Update the Spreadsheet/Graph
If Workbooks.Count = 1 Then
If TimeValue(Now()) <= TimeValue("06:30:00") Then
Call Macro3
Call Hide
Call Mail_Sheet_Outlook_Body
ActiveWorkbook.Save
Application.Quit
Else
If GetActiveWindow() = 0 Then
' We're running via the Task Scheduler: Update the Spreadsheet/Graph
If Workbooks.Count = 1 Then
Call Hide
Call Mail_Sheet_Outlook_Body
ActiveWorkbook.Save
Application.Quit
Else
Me.Close True 'save the changes and close the workbook
Application.DisplayAlerts = True
End If
End If
End If
End If
End If
End Sub

Admin
09-15-2014, 01:09 PM
Hi

Welcome to forum !

What happens if you run it manually (Pressing F8) by skipping the time criteria?

snb
09-15-2014, 02:11 PM
If

Elseif

Else

End if

gripper
09-16-2014, 12:10 AM
Hi snb,

The vb worked perfectly before I put the timing issue i, before all I needed was to run the sheet once, which created a new column for the current days information. Now I have to run it more than once per day, I don't want a new column created every time I run it.

I know I have probably made this more complicated than it needs to be as I am not very prificient at VB. I managed to get this far by manipulating VB that I found on the internet.

As for your suggestion to skip the timing criteria, I have no way of understanding where to put this within the VB I have. But thanks for the reply and at least thinking of a way round it.

Admin
09-16-2014, 07:40 AM
Hi

It's a Cross Post (http://www.ozgrid.com/forum/showthread.php?t=190886)

Please read Message to cross posters in my signature

gripper
09-16-2014, 11:50 PM
Hi,

Sorry, didn't realise both forums were linked, I have posted this on the Ozgrid forum.

VBA time value for task scheduler (http://www.ozgrid.com/forum/showthread.php?t=190886)

Thanks