john316swan
Board Regular
- Joined
- Oct 13, 2016
- Messages
- 66
- Office Version
- 2019
- Platform
- 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.
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.
And here is the example code from one of the workbooks:
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.
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.
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.