jrgreenman Posted May 26, 2009 Report Share Posted May 26, 2009 I have a macro that attaches a named file and then deletes the file. Even though the "file delete" command comes after the keystrokes that attach the file to the email, sometimes the file gets deleted before the attachment is actually attached. I've added in various delays to combat the problem, and they usually work, but not always. Does anyone know of a reliable way to detect when a named attachment is actually attached to an email? If I could test for that, I could put in a "wait" or something until I know for sure the attachment is actually attached. Thanks. Jace Quote Link to comment Share on other sites More sharing options...
kevin Posted May 26, 2009 Report Share Posted May 26, 2009 Could you 'flip' the logic? Move the file to be attached into a specific folder. Attach the file to the email (from that folder) and leave it. At the top of your macro (that will presumably run at a later time) look for files in that folder and delete them. You may put them in the Windows Temporary folder using something like '%Temp%\attachments'. Quote Link to comment Share on other sites More sharing options...
jrgreenman Posted August 3, 2009 Author Report Share Posted August 3, 2009 Sorry for the delayed reply. Not sure why I never saw this post. No matter. It sounds like that would leave the attachment in the temp folder until the NEXT time the macro is run, yes? So the most recent attachment would always be in there until the next time the macro runs? While I'd prefer to not leave the file lying around (it could contain sensitive empoyee information), the logic flip indeed oughtta do the trick. Thanks for the tip. Quote Link to comment Share on other sites More sharing options...
Cory Posted August 4, 2009 Report Share Posted August 4, 2009 Without getting into VBA I think Kevin's solution is best. However you could do as Kevin suggests and then create a macro to clean up a couple of minutes later. Or have a macro that runs from a rule in Outlook. You know, "Check messages after sending". Also have you considered using MEP's built in email feature? Quote Link to comment Share on other sites More sharing options...
jrgreenman Posted August 5, 2009 Author Report Share Posted August 5, 2009 Without getting into VBA I think Kevin's solution is best. However you could do as Kevin suggests and then create a macro to clean up a couple of minutes later. Or have a macro that runs from a rule in Outlook. You know, "Check messages after sending". Also have you considered using MEP's built in email feature? Hm. For some reason, yet again, I didn't receive an email notification when this reply was posted. I've confirmed my email address in the system is good, and even rec'd a couple notification last month. But this is the second one this week where I've not rec'd one. Strange. Anyway, I implemented Kevin's suggestion, but am rethinking it because I've found some use cases where things get a little wonky. First, I found that I frequently manually create docs to be attached and don't want to have to manually traverse to the temp directory (many layers down in the folder hierarchy) to place them there. Second, I often create multiple files and then subsequently attach them to different emails one-by-one. If the macro deletes *.* in the temp directory (I don't believe I have the file name any longer because for subsequent runs, it won't know what the actual name of the previously created file(s) was/were), the rest will disappear once I act on the first file. Same issue w/ the "clean up later" option. If I don't act on all the files before the housekeeping macro runs, I'd lose the files I'd created, but not yet acted on. Regarding Outlook rules, I don't see one that allows me to delete files in the file system after a message is sent (using OL 2007). Even so, I'm hoping to find a more efficient way to handle this without running the rule after each email message that goes out. Still, those were all good suggestions and got me brainstorming some more. If you think of anything else, feel free to lob. Quote Link to comment Share on other sites More sharing options...
paul Posted August 5, 2009 Report Share Posted August 5, 2009 Doesn't a message have an attachment property where you could either check whether the message has an attachment or count the number of attachments belonging to a message? For example, I'd have thought this code might provide a useful start? For Each Item In Inbox.Items For Each Atmt In Item.Attachments ........... Next Atmt Next Item Obviously Inbox is wrong. Quote Link to comment Share on other sites More sharing options...
Cory Posted August 5, 2009 Report Share Posted August 5, 2009 Regarding Outlook rules, I don't see one that allows me to delete files in the file system after a message is sent (using OL 2007). Even so, I'm hoping to find a more efficient way to handle this without running the rule after each email message that goes out.In the section where one specifies what one wants to do choose the action "Start Application". I often just run a batch file or one can probable run a macro with the command line switch to run a macro. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.