Felix Atagong
Active Member
- Joined
- Jun 27, 2003
- Messages
- 359
I have an Excel 2000 macro (that runs smoothly on Excel 2000) but that creates a 1004 run time error in Excel 2007 but only if certain conditions are met.
Basically it is a text parser that copies certain data to a worksheet "Country" if a certain countrycode is met and sends this worksheet by mail (but only if data has been copied). The macro loops through several 'countries' and opens, saves and closes files as long as they are empty. But once a mail has been send using the Sendmail command there will be a 1004 error at the next run in the loop (but only in Excel 2007).
The error given is as follows (on the save ABCTemp.xls code):
Run time error 1004
Microsoft Excel cannot access the file
C:\Program Files\Microsoft Office\Office12
There are several possibilities
The file name or path does not exist
The file is being used by another program
The workbook you are trying to save has the same name as a currently open workbook
If I disable this code the macro halts on the next save line (the ABC & ww(5) .txt) but with a slightly different error:
Run time error 1004
Cannot acces read-only document ABCDE.txt
Here is the code that used to work fine in Excel2000:
Any ideas why this doesn't work in 2007?
Basically it is a text parser that copies certain data to a worksheet "Country" if a certain countrycode is met and sends this worksheet by mail (but only if data has been copied). The macro loops through several 'countries' and opens, saves and closes files as long as they are empty. But once a mail has been send using the Sendmail command there will be a 1004 error at the next run in the loop (but only in Excel 2007).
The error given is as follows (on the save ABCTemp.xls code):
Run time error 1004
Microsoft Excel cannot access the file
C:\Program Files\Microsoft Office\Office12
There are several possibilities
The file name or path does not exist
The file is being used by another program
The workbook you are trying to save has the same name as a currently open workbook
If I disable this code the macro halts on the next save line (the ABC & ww(5) .txt) but with a slightly different error:
Run time error 1004
Cannot acces read-only document ABCDE.txt
Here is the code that used to work fine in Excel2000:
Code:
ChDir (WshShell.SpecialFolders("MyDocuments"))
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:="ABCTemp.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=True
ChDir (WshShell.SpecialFolders("MyDocuments"))
Sheets("Country").Move
ActiveWorkbook.SaveAs FileName:="ABC" & ww(5) & ".txt", _
FileFormat:=xlTextWindows, CreateBackup:=False
' ww(5) is an ISO country-code BE, FR, UK, DE, etc...
Application.DisplayAlerts = True
If Range("A9999").End(xlUp).Row > 1 Then
Application.Dialogs(xlDialogSendMail).Show _
arg1:="abcde@atagong.com", _
arg2:="LIST " & ww(5)
End If
ActiveWorkbook.Close SaveChanges:=False
Any ideas why this doesn't work in 2007?