Trouble automating a macro

rhess21

New Member
Joined
Apr 22, 2014
Messages
3
Hey everybody....first of all, even though this is my first post here, I have been using these forums as a tremendous resource to help develop some pretty awesome macros that have saved myself and my company an incredible amount of time, so thank you to those who contribute here.

On to my problem...I have a macro that I need to execute each night at 1 AM. This macro is opening up a spreadsheet, filtering data within this spreadsheet to new spreadsheets, and then emailing the new spreadsheets to the appropriate contacts. I created the below vbscript to execute this macro:

Code:
Dim objExcel

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\logfile.txt",2,true)


Set objExcel = CreateObject("Excel.Application")
objFileToWrite.WriteLine("1")


objExcel.Application.DisplayAlerts = False
objFileToWrite.WriteLine("2")
objExcel.Visible = False
objFileToWrite.WriteLine("3")


objExcel.Workbooks.Open "PATH OF WORKBOOK CONTAINING MACRO"
objFileToWrite.WriteLine("4")


objExcel.Run "Daily"
objFileToWrite.WriteLine("5")


objFileToWrite.Close
Set objFileToWrite = Nothing


objExcel.ActiveWorkbook.Close(0)
objExcel.Quit

As you can see above, I've added in some lines to write output to a text file so that I can track the progress of the the script. Whenever I launch the script by double clicking on it, everything executes perfectly. Whenever I try to run the script as a scheduled task, the log file doesn't make it past "3" so it appears to be getting stuck on
Code:
objExcel.Workbooks.Open "PATH OF WORKBOOK CONTAINING MACRO"

Does anybody have any experience with this? As far as the scheduled task goes, the user account set to run the task is an admin and the task is set to run w/ elevated rights. I've tried calling the script using several different methods, but none work. Any advice would be appreciated.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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