Task Scheduled Macro Workbooks not running

john316swan

Board Regular
Joined
Oct 13, 2016
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
I have this script that I have used 1000 times to schedule other tasks, but for some reason this time it isn't working and I'm thinking it's related to the exporting of pdf's but I have spent countless hours trying to fix and no resolution.

VBA Code:
'Write Excel.xls$  Sheet's full path here
strPath = "M:\Financial Aid\Regent\OL&CW\YR-22\CW22.xlsm"
strPath2 = "M:\Financial Aid\Regent\OL&CW\YR-23\CW23.xlsm"
strPath3 = "M:\Financial Aid\Regent\OL&CW\YR-23\OL23_NEW.xlsm"

'Create an Excel instance and set visibility of the instance
Set objApp = CreateObject("Excel.Application") 
objApp.Visible = True   'or False 

'Open workbook; Run Macro; Save Workbook with changes (not needed here); Close; Quit Excel
Set wbToRun = objApp.Workbooks.Open(strPath)
wbToRun.Save
wbToRun.close

Set wbToRun = objApp.Workbooks.Open(strPath2)
wbToRun.Save
wbToRun.close

Set wbToRun = objApp.Workbooks.Open(strPath3)
wbToRun.Save
wbToRun.close

objApp.Quit

When I run the vbs script manually, the workbooks open and run no problem, but the actual scheduled tasks just keeps running...and running...and running and nothing happens.
Actions.PNG
General.PNG
Triggers.PNG


And here is the example code from one of the workbooks:

VBA Code:
Option Explicit

Sub PrintCW()
    Dim StartRow As Integer, EndRow As Integer, i As Integer
    Dim CostWorksheet As String, AdmissionCopy As String, AcadYear As String, parentFolder As String
    Dim Msg As String, Living As String
    Dim CW As Worksheet
    'Dim startTime As String, endTime As String
    'startTime = Format(Now, "HH:MM:SS")
    
    Set CW = Worksheets("CW")
    AcadYear = "\YR-23\"
    parentFolder = "W:\DOCS\"
    AdmissionCopy = "X:\Financial Aid\2023-2024 Offer Letter & CW\"

    CW.Activate
    EndRow = Range("EndRow")
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
            
    'Now we're going to export all the docs
    For i = 1 To EndRow
    
        On Error Resume Next
        Range("RowIndex") = i
        If Range("W10") = True Then
            Application.Wait (Now + TimeValue("0:00:01"))
            If Range("S9") > 0 Then Living = "COSTSHEET ON" Else Living = "COSTSHEET OFF"
            CostWorksheet = parentFolder & [ID] & AcadYear & Living
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=CostWorksheet
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=AdmissionCopy & [last] & ", " & [first] & " " _
                & [ShortID] & " Estimated Cost Worksheet " & Format(Date, "MM-DD-YYYY")
        End If

    Next i

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
'endTime = Format(Now, "HH:MM:SS")
'MsgBox "Process Began on " & startTime & " and ended on " & endTime

End Sub

I am using a service account and it has all the proper drive permissions and the workbook is placed in a trusted location but I can't figure out why it won't run properly when scheduled. Any advice would be greatly appreciated.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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