Link to home
Start Free TrialLog in
Avatar of kks81
kks81

asked on

How can I copy the RTF-Body + Attachments and Insert them in an other E-Mail with vbscript

Hello,

I hope anybody can help me.
I have written an Outlook Script that opens an Item, using MAPI and Inserts the fields in an other Item.
Everything works fine, I can copy the subject with
Item.Subject = OldItem.Subject

Except of the body. It is in RTF Format and has embedded Items, for example jpg´s or bmp´s.
If I say
Item.Body = OldItem.Body I only get the Text but not the Attachements.

Has anybody an Idea how to manage it?

mfg

Jürgen St. from Germany
Avatar of stefri
stefri
Flag of France image

Attachements do not belong to message body but to OldItem.attachments collection

Avatar of kks81
kks81

ASKER

For sure, but I thought there might be an object to add both in one like
"Item.Body&Attachments = OldItem.Body&Attachments"

But I haven´t found anything. My Code looks like this, but is very slow on old 100MHz PCs and has an other disadvantage; If you insert a picture not as file but as object (Menu->Insert->object->from file), it is not in the attachment.

               '#########################
               'Anlagen einfügen
               Set fso = CreateObject("Scripting.FileSystemObject")
               Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
               strPath = fldTemp.Path & "\"
               For i = 1 to MyPH.Attachments.count
                    strFile = strPath & MyPH.Attachments(i).FileName
                    MyPH.Attachments(i).SaveAsFile strFile
                    Item.Attachments.Add strFile               ', , , objAtt.DisplayName
                    Item.Attachments(i).Position = MyPH.Attachments(i).Position
                    Item.Attachments(i).DisplayName = MyPH.Attachments(i).DisplayName
                    Item.Attachments(i).FileName = MyPH.Attachments(i).FileName
                    DoEvents     'Notwendig, damit die Dateien erst nachdem Sie eingefügt wurden gelöscht werden.
                    'fso.DeleteFile strFile
               Next
               Set fldTemp = Nothing
               Set fso = Nothing
               '#########################
ASKER CERTIFIED SOLUTION
Avatar of stefri
stefri
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kks81

ASKER

The purpose of the DoEvents was that I got an error as the
fso.DeleteFile strFile
wasn´t quoted.
Now I have changed the script a little (Read the filenames in an arrey and delete the files at the end of the script), so that the DoEvents is not longer needed.

I can´t use the .copy method, because I call the script from a customized form, with a button "New Version", then comes an inputbox "Please insert the number of the old Form" and I use the find-Method to open the old form and take over several filds.

I never thought of opening a new form from the old, but that could be the better way, less code and no trouble with attachments. I´ll try that.
Do you know an easy way to find and open the new created form?
Avatar of kks81

ASKER

Ok, fine!

This code works:
     set MyNameSpace = Application.GetNameSpace("MAPI")
     Set Folder0 = MyNameSpace.Folders("Postfach - Me")
     Set Folder1 = Folder0.Folders("Postausgang")
     Set objTemp = Item.copy
     Call objTemp.Move(Folder1)
     objTemp.Display

Thanks a lot for the idea, much easier, if I had thought about that, I could have saved lot of work.
You are welcome
Sharing problems allows new ideas to emerge.

Stefri