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
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
Attachements do not belong to message body but to OldItem.attachments collection
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->fro m file), it is not in the attachment.
'#########################
'Anlagen einfügen
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
strPath = fldTemp.Path & "\"
For i = 1 to MyPH.Attachments.count
strFile = strPath & MyPH.Attachments(i).FileNa me
MyPH.Attachments(i).SaveAs File strFile
Item.Attachments.Add strFile ', , , objAtt.DisplayName
Item.Attachments(i).Positi on = MyPH.Attachments(i).Positi on
Item.Attachments(i).Displa yName = MyPH.Attachments(i).Displa yName
Item.Attachments(i).FileNa me = MyPH.Attachments(i).FileNa me
DoEvents 'Notwendig, damit die Dateien erst nachdem Sie eingefügt wurden gelöscht werden.
'fso.DeleteFile strFile
Next
Set fldTemp = Nothing
Set fso = Nothing
'#########################
"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->fro
'#########################
'Anlagen einfügen
Set fso = CreateObject("Scripting.Fi
Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
strPath = fldTemp.Path & "\"
For i = 1 to MyPH.Attachments.count
strFile = strPath & MyPH.Attachments(i).FileNa
MyPH.Attachments(i).SaveAs
Item.Attachments.Add strFile ', , , objAtt.DisplayName
Item.Attachments(i).Positi
Item.Attachments(i).Displa
Item.Attachments(i).FileNa
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
ASKER
Ok, fine!
This code works:
set MyNameSpace = Application.GetNameSpace(" MAPI")
Set Folder0 = MyNameSpace.Folders("Postf ach - Me")
Set Folder1 = Folder0.Folders("Postausga ng")
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.
This code works:
set MyNameSpace = Application.GetNameSpace("
Set Folder0 = MyNameSpace.Folders("Postf
Set Folder1 = Folder0.Folders("Postausga
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
Sharing problems allows new ideas to emerge.
Stefri