Cross posted at Access World Forums
The attached sample file does not work properly in Excel 2010 on some computers.
The behaviour is very strange. Every second save in the loop succeeds.
If fails like this in our network on:
Dell Optiplex 755, Windows XP Professional, Excel 14.0.6123.5001
Dell Optiplex 9010SF, Windows 7 Professional, Excel 14.0.6123.5001
It works on:
Dell Optiplex 755, Windows XP Professional, Excel 2007
ASUS U36J, Windows 7 Professional, Excel 14.0.6112.5000
SaveAsError.xlsm
Private Sub test()
' Note that Winows 7 will not save a file into C:\ from a script
SaveExcel ("C:\test\test")
End Sub
Private Sub SaveExcel(ByVal OutputFileName As String)
Dim oExcel As Object 'Excel.Application
Dim oBook As Object 'Excel.Workbook
Dim oSheet As Object 'Excel.Worksheet
Dim SaveName As String
Dim n As Integer
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oExcel.UserControl = False
oBook.Activate
For n = 1 To 6
SaveName = OutputFileName & n & ".xlsx"
oSheet.Cells(1, 1) = n
Debug.Print SaveName
oBook.SaveAs SaveName
Debug.Print oBook.Saved
Next
Set oSheet = Nothing
oBook.Close
Set oBook = Nothing
oExcel.Quit
Set oExcel = Nothing
End Sub
Bookmarks