?
Solved

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

Posted on 2003-02-27
6
Medium Priority
?
669 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:kks81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:stefri
ID: 8051226
Attachements do not belong to message body but to OldItem.attachments collection

0
 

Author Comment

by:kks81
ID: 8055444
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
               '#########################
0
 
LVL 13

Accepted Solution

by:
stefri earned 300 total points
ID: 8056386
This is exactly the code I was thinking about. But what is the purpose of Doevents?


Apparently you want to copy myPH to a new mail, why not using myPh.copy and maybe later modify the messagebody?

Stefri
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:kks81
ID: 8056457
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?
0
 

Author Comment

by:kks81
ID: 8056849
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.
0
 
LVL 13

Expert Comment

by:stefri
ID: 8056965
You are welcome
Sharing problems allows new ideas to emerge.

Stefri
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question