I have quite an interesting problem. I have an XLSM spreadsheet with an Auto_Open macro that imports data from a CSV file and does some deletion/formatting. It then saves that sheet back over the existing CSV file. I then want to resave the workbook over the existing XLSM file. If Excel 2007 is closed before the macro runs, I get "Runtime error '1004': Cannot access 'Computer Name Listing.xlsm'". However, if I run the Auto_Open macro with the workbook already open, the problem does not happen. Any ideas? The problematic section of my code is below.
Application.DisplayAlerts = False
Dim oldName As String, oldPath As String, oldFormat As XlFileFormat
With ActiveWorkbook
oldName = .Name
oldPath = .Path
oldFormat = .FileFormat
.ActiveSheet.SaveAs Filename:="bla bla\Names.csv", FileFormat:=xlCSVWindows
.SaveAs Filename:=oldPath + "\" + oldName, FileFormat:=oldFormat
End With
Application.DisplayAlerts = True
If I enter debugging mode, the error line is the ".SaveAs Filename..." line.
Thanks for your help.
Bookmarks