Delete attachment

  • Thread starter Thread starter JoBless
  • Start date Start date
J

JoBless

Hi.

I'm playing arround with Micro-eye's vb6 'Outlook COM Add-in Template'

I've added an event to the 'objMailItem_AttachmentAdd', which deletes the
attachment (my intention is to manipulate the file and add the manipulated
file, before deleting the original attachment)

The deletion works fine when I choose the 'Insert'->'File' button to attach
the file (through the 'Insert File' dialog).
When I drag'n'drop the file to the mail-body, it deletes the file, but
outlook returns the error 'Operation failed'.

What can I do to avoid this error, when using drag'n'drop?

Regards

JoBless
 
Is it a MS bug, or?

Is it possible to determine if the attachment was added using drag'n'drop,
or by browsing to it?

If so, I'm willing to disable my vb routine for the drag'n'drop added files.

Regards

JoBless
 
You can't detect if drag and drop is used, and Outlook code doesn't
play that well with drag and drop. Just use an error handler and
handle the error or use On Error Resume Next and clear the error if it
occurs. That way your users won't see any error messages for your
code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
 
Are you sure the error is being generated by Outlook and not from an
unhandled error in your code? Show some of your code so I can try to
repro the error message here. Also post your Outlook and Windows
versions so I can repro your environment.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm

JoBless said:
I've tried the 'on error resume next' without success, but it seems that the
error isn't generated in my add-in, but when my add-in finishes it's
job?!?
 
The easiest way to reproduce the error is, if you download the sample code
form :
http://www.microeye.com/resources/Outlook COM Addin.zip

And enable the:Set objMailItem = objItem in ColInsp-NewInspector. Then add
the objMailItem_AttachmentAdd event, and simply add attachment.delete to
this event.

Then you can browse the file and attach it, without problems, but not
drag'n'drop it.

OS: WinXP Pro DK
Office XP XP developer

Btw. Now I'm having trouble deleting the attachment at all, in office 2K
pro, but not in office XP ?!?

Regards

Kim Andersen

Ken Slovak - said:
Are you sure the error is being generated by Outlook and not from an
unhandled error in your code? Show some of your code so I can try to
repro the error message here. Also post your Outlook and Windows
versions so I can repro your environment.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm

JoBless said:
I've tried the 'on error resume next' without success, but it seems that the
error isn't generated in my add-in, but when my add-in finishes it's
job?!?
 
I've run ItemsCB many times and never had a problem. Post the code you
are using and I can test it. What is WinXP Pro DK? Is that a German
language version of Windows? That I won't be able to repro.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
 
DK is Denmark, Europe

I'm not using the ItemsCB, but the com add-in template.

Here is some of my code:

Private Sub objMailItem_AttachmentAdd(ByVal Attachment As
Outlook.Attachment)
Dim FSO As Scripting.FileSystemObject, strInputFile As String, strOutputFile
As String
Dim TempFolder As String

strInputFile = Attachment.FileName
strInputFile = "(temp)" & strInputFile

'Find tempfolder
Set FSO = CreateObject("Scripting.filesystemobject")
TempFolder = FSO.GetSpecialFolder(2)
If Right(TempFolder, 1) <> "\" Then TempFolder = TempFolder & "\"

'vis besked
Message.Label1.Caption = "Konverterer"
Message.Show
Message.Refresh

'Gem filen temporert
If FSO.FileExists(TempFolder & strInputFile) Then FSO.DeleteFile (TempFolder
& strInputFile)
Attachment.SaveAsFile TempFolder & strInputFile

.........................................

Manuipulate the attached file

.........................................

'vent yderligere 2 sec.
Call Sleep(2000)

'Omd¸b (fjern (temp) fra destinationsfilen)
FSO.CopyFile TempFolder & strOutputFile, TempFolder & Right(strOutputFile,
Len(strOutputFile) - 6), True
FSO.DeleteFile TempFolder & strOutputFile, True
strOutputFile = Right(strOutputFile, Len(strOutputFile) - 6)

'Tilf¸j ny attachment (konverteret)
objMailItem.Attachments.Add TempFolder & strOutputFile, , , strOutputFile

'Slet temporer fil
FSO.DeleteFile TempFolder & strOutputFile, True

'Slet attachment
Attachment.Delete

'clean-up
Set FSO = Nothing

'Skjul message
Unload Message


End Sub


Regarding the outlook2000 issue, i've discovered that the file is deleted as
supposed, it just seems that it isn't deleted. Is it possible to refresh the
outlook form (or anything else), so the file allso is removed visualy ??

Regards

JoBless
 
I'd always start out using ItemsCB as my template, it has a lot of
stuff that works around various Outlook bugs and problems that we've
discovered over the years. And it also shows the best practices ways
to do Outlook things.

So the problem comes down to the attachment is really being deleted
but visually doesn't show that? Outlook caches open items. I'd release
the open item and get a new copy of it, that should force a refresh of
what's shown.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
 
As it seems to me, the ItemsCB is designed for another purpose, and doesn't
seem easy to edit for my purpose.

The only purpose for me is, to get the event of attachment add, and get the
mailitem, so I can manipulate it.

Is there any other version af ItemCB ´, that would be esier to use as
template?

Regards

JoBless

Ken Slovak - said:
I'd always start out using ItemsCB as my template, it has a lot of
stuff that works around various Outlook bugs and problems that we've
discovered over the years. And it also shows the best practices ways
to do Outlook things.

So the problem comes down to the attachment is really being deleted
but visually doesn't show that? Outlook caches open items. I'd release
the open item and get a new copy of it, that should force a refresh of
what's shown.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


JoBless said:
DK is Denmark, Europe

I'm not using the ItemsCB, but the com add-in template.

Here is some of my code:

Private Sub objMailItem_AttachmentAdd(ByVal Attachment As
Outlook.Attachment)
Dim FSO As Scripting.FileSystemObject, strInputFile As String, strOutputFile
As String
Dim TempFolder As String

strInputFile = Attachment.FileName
strInputFile = "(temp)" & strInputFile

'Find tempfolder
Set FSO = CreateObject("Scripting.filesystemobject")
TempFolder = FSO.GetSpecialFolder(2)
If Right(TempFolder, 1) <> "\" Then TempFolder = TempFolder & "\"

'vis besked
Message.Label1.Caption = "Konverterer"
Message.Show
Message.Refresh

'Gem filen temporert
If FSO.FileExists(TempFolder & strInputFile) Then FSO.DeleteFile (TempFolder
& strInputFile)
Attachment.SaveAsFile TempFolder & strInputFile

........................................

Manuipulate the attached file

........................................

'vent yderligere 2 sec.
Call Sleep(2000)

'Omd¸b (fjern (temp) fra destinationsfilen)
FSO.CopyFile TempFolder & strOutputFile, TempFolder & Right(strOutputFile,
Len(strOutputFile) - 6), True
FSO.DeleteFile TempFolder & strOutputFile, True
strOutputFile = Right(strOutputFile, Len(strOutputFile) - 6)

'Tilf¸j ny attachment (konverteret)
objMailItem.Attachments.Add TempFolder & strOutputFile, , , strOutputFile

'Slet temporer fil
FSO.DeleteFile TempFolder & strOutputFile, True

'Slet attachment
Attachment.Delete

'clean-up
Set FSO = Nothing

'Skjul message
Unload Message


End Sub


Regarding the outlook2000 issue, i've discovered that the file is deleted as
supposed, it just seems that it isn't deleted. Is it possible to refresh the
outlook form (or anything else), so the file allso is removed visualy ??

Regards

JoBless
 
There is only 1 version of ItemsCB available, and most of what's in it
is extremely valuable for the workarounds for Outlook bugs it shows.
If you don't want to use that template then don't.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
 
Back
Top