Windows Server - WS2008 Task Scheduler VBA - cannot open file

Asked By trevor bonifie on 03-Jun-11 05:51 PM
Hello,

I am trying to set up task scheduler in Windows Server 2008 to run an excel VBA script.  For the record, this exact thing works just fine in Windows 7, but won't work in WS2008 for some reason.

The task is basically just to open the excel file each night at 10PM. 

The excel file, when opened, runs SQL queries, compiles data, then creates tables and outputs a powerpoint 2007 presentation.

The problem occurs when the VBA code goes to open up the Powerpoint template file.  It simply won't open the file.

Here is the "offending" code snippet

Set PP = New PowerPoint.Application

PP.Visible = msoCTrue

Template_Path = "C:\Path\To\Powerpoint\Template"
Set PPpres = PP.Presentations.Open(Template_Path)


The last line of code shown results in an error, "PowerPoint could not open the file. Error -2147467259".  (Actually, the PP.Visible = msoCTrue blows up as well, but I've commented that out when trying it from the scheduler).

The whole thing works fine if I simply open the excel file manually.  But when triggered from Task Scheduler, it blows up every time.

Any clues?
Riley K replied to trevor bonifie on 03-Jun-11 10:20 PM
Yes, the Task Scheduler WILL execute .vbs files but you need to give
yourself some eyes to see what the problem is. Instead of invoking the .vbs
file directly, invoke it through a batch file like so:
@echo off
echo %date% %time% %username% >> c:\test.txt
cscript //nologo c:\pher.vbs 1>>c:\test.txt 2>>&1
echo %date% %time% >> c:\test.txt

Now run this file via the Task Scheduler, then examine the file c:\test.txt.
I expect that all will become very clear. Note that you could replace
cscript.exe with wscript.exe, depending on which interpreter you wish to
use.

Refer this link

http://
trevor bonifie replied to Riley K on 07-Jun-11 01:16 PM

Thanks, but I've already done that.  (and it's not VBS, it's VBA for Excel, although the difference is minor).

In addition, I have an error handler in the excel VBA code which spits out the error to a log file.  This is how I know the exact error I'm getting (and posted above).

here is the file I used to invoke it:


@echo off
echo %date% %time% %UserName% >> c:\PATH\TO\test.txt
"C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" "C:\PATH\TO\MASTER.xlsm"
echo %date% %time% >> c:\PATH\TO\test.txt

 

Since I'm running Excel and not a direct scripting tool, I don't think I'm going to get much more out of it than what I have.  I already have the error output from Excel as posted above.

 

Any more hints?  Am I doing it wrong?

---

 

So just to narrow things down, I wrote a new excel vba script into a blank file, here is the entirety of the code:

 

 

Public Sub workbook_open()

Dim PP As PowerPoint.Application
Dim PPpres As PowerPoint.Presentation

On Error GoTo writelog

write_log ("*****START*****: " & Format(Date, "MMMM DD, YYYY") & " " & Format(Time, "H:MM AM/PM"))

write_log ("Starting up Powerpoint")

Set PP = New PowerPoint.Application

write_log ("Application activated, now trying to make PPT visible")

PP.Visible = msoCTrue

write_log ("Powerpoint visible = true completed")

Template_Path = "C:\PATH\TO\Template.ppt"

write_log ("Accessing Template, path is: " & Template_Path)

Set PPpres = PP.Presentations.Open(Template_Path)

write_log ("template open")

writelog:

If Err.Number <> 0 Then

write_log ("*****ERROR*****: PPT: Exiting PPT scripts")
write_log ("*****ERROR DESCRIPTION*****: " & Err.Description & " #:" & Err.Number)

End If
  
On Error Resume Next
PPpres.Close

PP.Quit

write_log ("*****END*****: " & Format(Date, "MMMM DD, YYYY") & " " & Format(Time, "H:MM AM/PM"))

Application.ActiveWorkbook.Saved = True
Application.DisplayAlerts = False
Application.Quit

End Sub

Public Sub write_log(logtext As String)

fnum = FreeFile()
Open "C:\PATH\TO\filtest.log" For Append As fnum
Print #fnum, logtext
Close #fnum

End Sub

Here is the output when I run it by double-clicking the file, everything's peachy:

*****START*****: June 07, 2026 9:57 AM
Starting up Powerpoint
Application activated, now trying to make PPT visible
Powerpoint visible = true completed
Accessing Template, path is: C:\PATH\TO\Template.ppt
template open
*****END*****: June 07, 2026 9:57 AM


And here is the output when I run it via Task Scheduler:

 

*****START*****: June 07, 2026 10:00 AM
Starting up Powerpoint
Application activated, now trying to make PPT visible
Powerpoint visible = true completed
Accessing Template, path is: C:\PATH\TO\Template.ppt
*****ERROR*****: PPT: Exiting PPT scripts
*****ERROR DESCRIPTION*****: PowerPoint could not open the file. #:-2147467259


 

At this point, the script seems to hang, PowerPoint doesn't quit, Excel doesn't quit (I have to force them to close via Task Manager). 

Any help would be much appreciated.  I'm kind of lost at this point.

trevor bonifie replied to Riley K on 07-Jun-11 02:34 PM
I read through the thread you recomended, unfortunately, that hasn't solved this, either. 

I've tried setting the folder (and subfolder) permissions to allow everyone full access, but still get the same results.

I've tried putting the file that needs to be opened in the public documents folder, and again checked permissions on everything allowing everyone full control, still same results.

sigh...  help?
trevor bonifie replied to trevor bonifie on 09-Jun-11 06:08 PM
Well, I finally figured it out via this link.  What a crock!

http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91?prof=required 

Here are the instructions:

This solution is ...

・Windows 2008 Server x64
  Please make this folder.

  C:\Windows\SysWOW64\config\systemprofile\Desktop

・Windows 2008 Server x86

  Please make this folder.

  C:\Windows\System32\config\systemprofile\Desktop

  ...instead of dcomcnfg.exe.

This operation took away office automation problems in my system.