bamako1
06-01-2010, 03:20 AM
Hi there,
I have the following code which does some formatting of an excel file and then save the file with the same name.
The code runs fine on Microsoft Excel 2003 but when I run the same code on a PC with Microsoft Excel 2007 installed I get the following error message. Any ideas?
“Windows Script host
Line: 59
Char: 17
Error: Document not saved
Code: 800A03EC
Source: Microsoft Office Excel”
----------
Dim sfile
Set sfile = WScript.Arguments
Dim objXL
Set objXL = CreateObject("Excel.Application")
With objXL
.Workbooks.Open (sfile(0))
'Wrap text for the heading(row4)
.Application.Rows("4:1500").Select
With .Application.Selection
.WrapText = True
End With
'Adjust row height
.Application.Rows("3:1500").EntireRow.AutoFit
.Application.Rows("5:1500").Select
'Adjust column width
.Application.Cells.Select
.Application.Cells.EntireColumn.AutoFit
'Fix column width
.Application.Columns("B:B").Select
.Application.Selection.ColumnWidth = 40.00
.Application.Columns("V:V").Select
.Application.Selection.ColumnWidth = 40.00
'FreezePane
.Application.Range("B5").Select
.Application.ActiveWindow.FreezePanes = True
'Add Border
.Application.Range("3:1500").BORDERS.Color = RGB(0, 0, 0)
'Bold font for non-zero values
const xlCellValue = 1
const xlGreater = 5
.Application.Range("AG5:AL1500").Select
.Application.Range("AL1500").Activate
.Application.Selection.FormatConditions.Delete
.Application.Selection.FormatConditions.Add xlCellValue, xlGreater, "0"
With .Application.Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
End With
'Auto filter
.Application.Rows("4:4").Select
.Application.Selection.AutoFilter
.Application.Selection.AutoFilter
.Application.Selection.AutoFilter
.Application.Range("B5").Select
'Save and Close
.Workbooks(1).Save
.Workbooks(1).Close (False)
.Application.Quit
End With
Set objXL = Nothing
I have the following code which does some formatting of an excel file and then save the file with the same name.
The code runs fine on Microsoft Excel 2003 but when I run the same code on a PC with Microsoft Excel 2007 installed I get the following error message. Any ideas?
“Windows Script host
Line: 59
Char: 17
Error: Document not saved
Code: 800A03EC
Source: Microsoft Office Excel”
----------
Dim sfile
Set sfile = WScript.Arguments
Dim objXL
Set objXL = CreateObject("Excel.Application")
With objXL
.Workbooks.Open (sfile(0))
'Wrap text for the heading(row4)
.Application.Rows("4:1500").Select
With .Application.Selection
.WrapText = True
End With
'Adjust row height
.Application.Rows("3:1500").EntireRow.AutoFit
.Application.Rows("5:1500").Select
'Adjust column width
.Application.Cells.Select
.Application.Cells.EntireColumn.AutoFit
'Fix column width
.Application.Columns("B:B").Select
.Application.Selection.ColumnWidth = 40.00
.Application.Columns("V:V").Select
.Application.Selection.ColumnWidth = 40.00
'FreezePane
.Application.Range("B5").Select
.Application.ActiveWindow.FreezePanes = True
'Add Border
.Application.Range("3:1500").BORDERS.Color = RGB(0, 0, 0)
'Bold font for non-zero values
const xlCellValue = 1
const xlGreater = 5
.Application.Range("AG5:AL1500").Select
.Application.Range("AL1500").Activate
.Application.Selection.FormatConditions.Delete
.Application.Selection.FormatConditions.Add xlCellValue, xlGreater, "0"
With .Application.Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
End With
'Auto filter
.Application.Rows("4:4").Select
.Application.Selection.AutoFilter
.Application.Selection.AutoFilter
.Application.Selection.AutoFilter
.Application.Range("B5").Select
'Save and Close
.Workbooks(1).Save
.Workbooks(1).Close (False)
.Application.Quit
End With
Set objXL = Nothing