Log in

View Full Version : automatically saved attachments - open with Excel - format warning message



big_bear
08-20-2007, 04:28 AM
Dear all,

Thank you for taking the time to read this, perhaps with an eye to helping me out...

Like many others, I have been developing a way of dealing automatically with email attachments in the form of daily reports.

My save method is an amalgamation of Sue Mosher's neat little code (posted all over the place) and the one from the knowledge base on this website. (Sorry, I can't post links as a newbie)

What I have works wonderfully, but when I try to open my (txt) files with a macro in Excel, using 'opentext' I get a warning telling me (some paraphrasing):

This file is not in a recognizable format:
If you know the file is <never going to work> click cancel and <get a brain>
If you suspect the file is damaged, click Help <but you're basically screwed>
If you still want to see what text is in the file <good luck to you> click OK

If I click OK, my macro continues and works as it should.

If I save the files manually from Outlook (as I had been doing, until I wrote this macro), the warning doesn't come up.

Even if I try to open the automatically saved files, I get the same warning message.

These three points lead me to believe I need to define the format of the txt file as a text file when I save it, but how?

With some experience of these forums I suspect rather than a straight answer someone will kindly explain how I've actually completely missed the point. Sorry if my ignorance makes the question awkward!

Thanks, Neil

geekgirlau
08-20-2007, 05:12 PM
Can you post the code you are using to save the text file? Just copy and paste the code into your post, and use the VBA button to insert the vba tags.

big_bear
08-21-2007, 01:29 AM
The lack of mind reading really disappoints...
(this runs from a "run a script" rule, msg is the mailitem passed into the routine by the rule)


' <defining variables>
If msg.Attachments.Count > 0 Then
For i = 1 To msg.Attachments.Count
Set olAtt = msg.Attachments(i)
If Right(olAtt.FileName, 3) = "txt" Then
olAtt.SaveAsFile "C:\dailyreports\text\" & olAtt.FileName
ElseIf Right(olAtt.FileName, 3) = "csv" Then
olAtt.SaveAsFile "C:\dailyreports\comma\" & olAtt.FileName
End If
Next i
End If

' <releasing variables>


Pretty basic stuff really, it's the text files that give the error message, thanks for looking...

geekgirlau
08-22-2007, 12:38 AM
It doesn't appear to be anything the Outlook code is doing (as you say, all it does is save the attachment). What about the code you are using in Excel to open it?

We're working on the mind-reading forum for the board, but it's still under development so bear with us! :tongue2:

big_bear
08-22-2007, 01:36 AM
well, I use the opentext command, but I'm pretty confident that's not the problem, as the error message appears even if I try to open the files manually (I didn't make this terribly clear in my first post).

Oddly, it's not a problem on the computer of the guy I've done this for, but I'd still like to crack it!

Charlize
08-30-2007, 03:27 PM
Does the directory of text exists ? Do you use option compare text on top of your module ? Maybe try this : olAtt.SaveAsFile Left("C:\dailyreports\text\" & olAtt.FileName, 255)