Original Attachment not removed

Status
Not open for further replies.
S

sd

hello

I've VSTO Addin for Outlook 2007.

I'm adding a dummy attachment in BeforeAttachment event & removing

original attachment.

But the attachment list still shows me original attachment along with

dummy attachment.

Besides this when I drag drop or insert attachment the cursor position

changes.

I also need to insert a link at current cursor position.so the cursor

position should not change

for proper link insertion.

Below is the code I'm using -

strMyTmpFilePath = IO.Path.Combine(strMyTmpFilePath,

strMyTmpFileName)

IO.File.AppendAllText(strMyTmpFilePath, "this is a dummy

file")

CurrentMailItem.Attachments.Add(strMyTmpFilePath)

IO.File.Delete(strMyTmpFilePath)

Cancel = True

'Code to add Link at cursor position

Dim ObjSel As Object = CurrentInsp.WordEditor.Application.Selection

With ObjSel

Dim Rg As Object

> MoveRight(Unit:=2, Count:=1) 'wdWord=2

Rg = .range

> Hyperlinks.Add(Anchor:=Rg, Address:=strAttachmentURL _

, TextToDisplay:=strNewLink.ToString)

> InsertAfter(" ")

End With

If Rg IsNot Nothing Then Marshal.FinalReleaseComObject(Rg)

If ObjSel IsNot Nothing Then Marshal.FinalReleaseComObject(ObjSel)

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Try saving the item after you add your new attachment and again after you

remove the old one.

"sd" <dshubhangi@gmail.com> wrote in message

news:615ab412-3a80-4272-9f4d-b930ba2974c8@b25g2000prb.googlegroups.com...
> hello

> I've VSTO Addin for Outlook 2007.
> I'm adding a dummy attachment in BeforeAttachment event & removing
> original attachment.
> But the attachment list still shows me original attachment along with
> dummy attachment.
> Besides this when I drag drop or insert attachment the cursor position
> changes.
> I also need to insert a link at current cursor position.so the cursor
> position should not change
> for proper link insertion.
> Below is the code I'm using -

> strMyTmpFilePath = IO.Path.Combine(strMyTmpFilePath,
> strMyTmpFileName)
> IO.File.AppendAllText(strMyTmpFilePath, "this is a dummy
> file")
> CurrentMailItem.Attachments.Add(strMyTmpFilePath)
> IO.File.Delete(strMyTmpFilePath)
> Cancel = True
> 'Code to add Link at cursor position
> Dim ObjSel As Object = CurrentInsp.WordEditor.Application.Selection
> With ObjSel
> Dim Rg As Object
> .MoveRight(Unit:=2, Count:=1) 'wdWord=2
> Rg = .range
> .Hyperlinks.Add(Anchor:=Rg, Address:=strAttachmentURL _
> , TextToDisplay:=strNewLink.ToString)
> .InsertAfter(" ")
> End With
> If Rg IsNot Nothing Then Marshal.FinalReleaseComObject(Rg)
> If ObjSel IsNot Nothing Then Marshal.FinalReleaseComObject(ObjSel)

> Thanks
 
S

sd

Thanks Ken

I saved item after new attachment addition & also after removing the

old one.But no success.Attachment list not refreshed.

Also I don't want to save item (if the user cancels send then I will

have to remove this item from drafts).I reassigned the body

format,that refreshes the attachment list.But in plain text mode link

is not recognized (it is displayed as plain text) & cursor position

again set to starting of message body .

Is there any way so the link gets recognized & also cursor position

doesn't change? If I don't add new attachment ,just remove the old

one & add the link then there is no problem link is recognized &

cursor position also not changed.
 
K

Ken Slovak - [MVP - Outlook]

I don't know about forcing a refresh as well as not changing the cursor

position. However, that's not really an issue, since you can always get the

cursor position first before it changes. That should help.

See if faking out Outlook helps, something like item.Body = item.Body. But I

think you're going to have to save. I usually use a flag in those cases,

first I check the Saved property and then I flag my save if needed, then I

handle the Write() event on the item and if I didn't fire that event by

saving it's the user who did it (or auto-save). Then I can work out if I

need to delete the item from Drafts if necessary.

"sd" <dshubhangi@gmail.com> wrote in message

news:3d84b636-4781-4edb-82ff-21e2f8edfdf2@l35g2000pra.googlegroups.com...
> Thanks Ken
> I saved item after new attachment addition & also after removing the
> old one.But no success.Attachment list not refreshed.
> Also I don't want to save item (if the user cancels send then I will
> have to remove this item from drafts).I reassigned the body
> format,that refreshes the attachment list.But in plain text mode link
> is not recognized (it is displayed as plain text) & cursor position
> again set to starting of message body .
> Is there any way so the link gets recognized & also cursor position
> doesn't change? If I don't add new attachment ,just remove the old
> one & add the link then there is no problem link is recognized &
> cursor position also not changed.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Auto Forward - Include Attachment and change Subject depending on original sender Outlook VBA and Custom Forms 3
A Creating a rule that both forwards the original attachment and uses a template Using Outlook 11
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
S Email Generated from another program and then edited sends original email. Using Outlook 2
T Original email text not shown when replying or forwarding the email. Using Outlook 6
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
B disappearing original when attach to email Using Outlook 1
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
B Outlook 2013 erratically deleting original file that is attached Using Outlook 0
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
R Retain Original Message When Forwarding With Macro Outlook VBA and Custom Forms 3
D Keep Original html body when forwarding an email Outlook VBA and Custom Forms 7
F Move mails from Deleted Items folder back to its original folder where the mails got deleted Using Outlook 0
Diane Poremsky Foward a Message and CC the Original Recipients Using Outlook 0
H send reminder if no reply received on first or original email using macro Using Outlook 2
H Keep Original email unread after autoreply Outlook VBA and Custom Forms 2
oliv- Why custom form is different from original ipm.contact ? Outlook VBA and Custom Forms 4
S Reply & Forward Date in original message incorrect Using Outlook 2
E Button in body of email to approve/reject with original text Using Outlook 1
S Need CC: to show the original To: recip[ients Using Outlook 4
R Forwarding and keeping Original intact Using Outlook 3
B Auto reply using macro include original email Using Outlook 4
J Image in original e-mail is hyperlinked when a reply with the image is hyerplinked Exchange Server Administration 1
J Adding original email text to outlook message template Outlook VBA and Custom Forms 2
L Creating a Task from Email and Attaching Original Email Outlook VBA and Custom Forms 6
L Auto Forward without presenting the original sender Outlook VBA and Custom Forms 1
J How to redesign the Contact form without losing the original layout? Using Outlook 2
A automatically remove flag from original message when a response was received Using Outlook 2
C Remove iCloud so I can have original outlook calendar and contacts Using Outlook 43
C Hover display of DL shows original owner, not current Using Outlook 2
S Outlook 2k/2k3 Reply or Forward: Signature image replaced by original sender Using Outlook 3
M 2010: sorting by ORIGINAL send date Using Outlook 1
C Create a rule to only check new content in email - disregard original content Using Outlook 3
R Recall Email Message when i'm not the original sender - Outlook 2010 Using Outlook 2
C Outlook/Exchange 2010 Recover Deleted Items to original folder Using Outlook 2
P Reply to original sender, not to forwarder ? Outlook VBA and Custom Forms 1
S -> [O2007]: get the message HTML original source code? Outlook VBA and Custom Forms 6
R Auto Reply with Original Email and any attachments Outlook VBA and Custom Forms 1
R keep track of the original sender Outlook VBA and Custom Forms 3
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
K Outlook Office 365 VBA download attachment Outlook VBA and Custom Forms 2
P Sending email from outlook IMAP to GMAIL where embedded images are added as attachment Using Outlook 1
S save attachment with date & time mentioned inside the file Outlook VBA and Custom Forms 0
O VBA Outlook Message Attachment - Array Index Out of Bounds Outlook VBA and Custom Forms 0
A Edit attachment Save and Reply Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
B Outlook 2010 Opening Mail Attachment Using Outlook 2
A Warning When Opening attachment Using Outlook 7
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2

Similar threads

Top