0

I have a .bat file that is one line long and calls up a vb script that specifically opens an excel file and runs some macros:

cscript priordays.vbs "C:\PATHANME\FILENAME.xlsm"

When I run it by double clicking, it runs fine and successfully.

When I run in task scheduler, it says it ran successfully (code 0x0), but the script does not execute. I've got it set to run with highest permissions, regardless of whether or not the user is logged in, wake machine, etc. Still nothing.

For those asking what's in the vb script, it's:

Dim arts, objExcel

Set args = WScript.ARguments
Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Open args(0)
objExcel.visible = True

objExcel.Run "Macro1"
objExcel.Run "Macro2"
objExcel.Run "Macro3"

objWorkbook.Close

objExcel.Quit

I found that code elsewhere on this site, along with the instructions on using the .bat file. If there's a way to run it all from the script, and try to launch the script from task scheduler, I'm fine to do that as well.

  • The problem is that office com automation doesn't work in a scheduled task out of the box. It's quite tricky to get this to actually work as it involves changing permissions in the 32bit dcom management console (C:\Windows\SysWOW64\dcomcnfg.exe). I don't have a proper documentation at hand atm, but that should point you into the right direction. – megamorf Feb 27 '17 at 14:10
  • I can find the file, but I'm not sure what to do with it. I am well out of my depth, I believe. – mbald23 Feb 27 '17 at 14:12
  • You can try making a startup macro for office and then just run cscript Excel.exe and then the startup macro will run and close excel. – RamonRobben Feb 27 '17 at 14:14
  • Here's a MS link that explains how to do it: blogs.technet.microsoft.com/… – megamorf Feb 27 '17 at 14:15
  • @megamorf, I went in and gave all permissions, but it didn't change anything. – mbald23 Feb 27 '17 at 14:28
0

As @Megamorf said in his comment its really tricky to do. So you would be better off using a startup macro and a sheduled start to achieve your goal.

How it works? You make a startup macro for excel which will start everytime that excel starts.

If you combine this with the scheduled start using the at command from the following question: Running bat file using Windows scheduler

For you the AT command would be e.x

at 20:30 /every:M,T,W,Th,F,S,Su "excel.exe"

This will start excel every day at 8:30 PM. Excel will run the startup macro.

How to Cancel a Scheduled Task

  1. Click Start, point to Programs, point to Accessories, and then click Command Prompt.
  2. At the command prompt, type the following line, and then press ENTER to display a list of currently running services:

    net start

  3. If Task Scheduler is not displayed in the list, type the following line, and then press ENTER:

    net start "task scheduler"

  4. At the command prompt, type the following line (use the parameters that are appropriate to your situation), and then press ENTER:

    at \computername id /delete | /delete/yes

\\computername is a computer that is in a network. You do not have to fill that in.

| improve this answer | |
  • Giving this a shot momentarily. If I want to stop this at some point, what would I used as my stop script? – mbald23 Feb 27 '17 at 15:24
  • @mbald23 when you visit the link from at command and scroll down a but you will see instructions on how to cancle the command. I'll add it to my answer aswell. – RamonRobben Feb 27 '17 at 15:31
  • Ran into an issue. Not sure if there's a way to upload screenshots, but command rejected it as invalid. – mbald23 Feb 27 '17 at 15:39
  • @mbald23 you can upload screenshots to a site from imgur or something and post the link. – RamonRobben Feb 27 '17 at 15:41
  • imgur.com/a/He0Lb – mbald23 Feb 27 '17 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.