MedievalDragon
New Member
- Joined
- Jan 21, 2010
- Messages
- 4
All,
I am having a strange issue. I can run my vbscript from the command prompt or by double clicking on it and all is well. The script starts a hidden excel instance and updates the data and saves the file or creates if not there.
The problem is when I start the script via task scheduler. I see the excel instance start and process data if the file does not exist but it does not save the new file. If the file exists, excel starts but does not look like it is opening the file to process any data. below is my test vbs file...
Any help would be greatly appreciated.
Excel 2007 and 2003 on server 2008
I am having a strange issue. I can run my vbscript from the command prompt or by double clicking on it and all is well. The script starts a hidden excel instance and updates the data and saves the file or creates if not there.
The problem is when I start the script via task scheduler. I see the excel instance start and process data if the file does not exist but it does not save the new file. If the file exists, excel starts but does not look like it is opening the file to process any data. below is my test vbs file...
Any help would be greatly appreciated.
Excel 2007 and 2003 on server 2008
Code:
Option Explicit
'==============================================================='
'==============================================================='
'=========================='
' Define constants '
'=========================='
Dim oFileSystem
Dim oTextFile
Dim oGrantUsersTextFile
Dim oDenyUsersTextFile
Dim oExcelApplication
Dim oExcelWorkbook
Dim oExcelSheet
Set oFileSystem = CreateObject("Scripting.FileSystemObject")
Dim sCurrentDirectory
''Get and save the current working directory
sCurrentDirectory = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path
wscript.echo "dbg1: " & sCurrentDirectory
Dim sExcelFilePath
sExcelFilePath = sCurrentDirectory & "\testfile.xlsx"
'' Create excel application
Set oExcelApplication = CreateObject("Excel.Application")
oExcelApplication.Visible = True
oExcelApplication.DisplayAlerts = False
oExcelApplication.AlertBeforeOverwriting = False
If oFileSystem.FileExists(sExcelFilePath) Then
wscript.echo "db2 (fileexist-true): " & sCurrentDirectory & "\testfile.xlsx"
Set oExcelWorkbook = oExcelApplication.Workbooks.Open(sExcelFilePath)
Set oExcelSheet = oExcelWorkbook.Sheets(1)
oExcelSheet.Cells(1,1) = Now
oExcelWorkbook.Save
else
wscript.echo "db2 (fileexist-false): " & sCurrentDirectory & "\testfile.xlsx"
' Add workbook
Set oExcelWorkbook = oExcelApplication.Workbooks.Add
' Select sheet1 and rename
Set oExcelSheet = oExcelWorkbook.Sheets(1)
oExcelSheet.Name = "GRANT Users"
oExcelWorkbook.SaveAs(sExcelFilePath)
End If
' Save & Close excel application
oExcelWorkbook.Close
oExcelApplication.Quit