AutoTrigger

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this script and is only working if I do debug (Alt+f8), but if i run the report it is not doing the doevent part, no error at all.
Any help as what is wrong.

Ref the screen shot for time to auto trigger, or to do Doevent for the condition match's scheduledTimes = timeValue(now)

VBA Code:
Sub RunFileAtScheduledTime()
    Dim filePath As String
    Dim scheduledTimes(1 To 3) As Date ' Array to store scheduled times
    Dim otherWorkbook As Workbook
    Dim i As Integer

    ' Set the path to the other workbook
    filePath = "C:\Viral Shah\Automation\Hourly Pending Tickets\Hourly Pending Tickets V2.xlsm"

    ' Read the scheduled times from cells C3, D3, and E3 of the "RunReportTime" sheet
    scheduledTimes(1) = Sheets("RunReportTime").Range("C3").value
    scheduledTimes(2) = Sheets("RunReportTime").Range("D3").value
    scheduledTimes(3) = Sheets("RunReportTime").Range("E3").value

    ' Loop indefinitely
    Do
        ' Loop through scheduled times
        i = 1 ' Initialize i to start from the first scheduled time
        Do While i <= 3
            ' Check if the current scheduled time has passed
            If scheduledTimes(i) < timeValue(Now) Then
                ' Move to the next scheduled time if the current one has passed
                i = i + 1
            Else
                ' Wait until current scheduled time matches the current time
                Do Until scheduledTimes(i) = timeValue(Now)
                    DoEvents
                Loop
                
                ' Open the other workbook
                Set otherWorkbook = Workbooks.Open(filePath)

                ' Call the allrun subroutine from the other workbook
                Application.Run "'" & otherWorkbook.Name & "'!allrun"

                ' Close the other workbook
                otherWorkbook.Close SaveChanges:=True

                ' Exit the loop to start over the outer loop
                Exit Do
            End If
  
        Loop
    Loop
End Sub

[ATTACH type="full"]106511[/ATTACH]
 

Attachments

  • 1707377214078.png
    1707377214078.png
    62.1 KB · Views: 6

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Have you thought about splitting your procedure into two, and using Application.OnTime? Coded this way, it wouldn't even matter if the times weren't in order.
VBA Code:
Sub ExecuteOnTime()
    Const clngRow As Long = 3
    Dim lngCol As Long
    Dim datToStart As Date
    ' Read the scheduled times from cells C3, D3, and E3 of the "RunReportTime" sheet
    For lngCol = 3 To 5
        datToStart = Sheets("RunReportTime").Cells(clngRow, lngCol).Value
        Application.OnTime datToStart, "RunReport", datToStart + TimeValue("00:00:30")
    Next
End Sub

Sub RunReport()
    Dim otherWorkbook As Workbook
    Const filePath As String = "C:\Viral Shah\Automation\Hourly Pending Tickets\Hourly Pending Tickets V2.xlsm"
    Set otherWorkbook = Workbooks.Open(filePath)

    ' Call the allrun subroutine from the other workbook
    Application.Run "'" & otherWorkbook.Name & "'!allrun"

    ' Close the other workbook
    otherWorkbook.Close SaveChanges:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,145
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top