I regularly receive forwarded emails that come as Outlook formatted .msg files. These emails were forwarded as attachments from another exchange server. If I drag the attached messages to my Inbox, they show up just like any other email. I would like to find an automated way to extract these attached emails to my inbox and delete the original messaged that contained the .msg file.
I’m sure this can be accomplished through a rule in conjunction with an Outlook VBA, but I lack the skill to write this code from scratch.
Any pointers or sample code to get me started?
Here is how I would do it. However, I will give you pieces of code which you will have to merge together.
Logic:
Extract the attachment and save it to say C:\
Use the method CreateItemFromTemplate() to open the .msg file. More about it HERE
Move the message to the relevant folder
Code for Extracting attachments: Covered HERE
Code for opening the .msg file:
Sub CreateFromTemplate()
Dim MyItem As Outlook.MailItem
Set MyItem = Application.CreateItemFromTemplate("C:\Blah Blah.msg")
MyItem.Display
End Sub
Now you have the handle to the .msg i.e MyItem, simply move it to the relevant folder and then delete the original email
Code for moving to a different folder: Covered HERE. If you search google, you will get more sample codes for this.
Hope this gets you on the right path.
Related
I have a folder with 200ish msg files from Outlook which I need to put in a single CSV where each column represents one msg with corresponding subject, body, to etc.
Any good idea how to do that without doing it manually?
You can automate Outlook and Word to get the job done. For example, you can automate Outlook from Excel or otherwise in VBA. Read more about that in the Automating Outlook from a Visual Basic Application article.
The Outlook object model provides the NameSpace.OpenSharedItem method which opens a shared item from a specified path or URL. This method is used to open iCalendar appointment (.ics) files, vCard (.vcf) files, and Outlook message (.msg) files. The type of object returned by this method depends on the type of shared item opened. So, you can use that method to open the MSG file from the disk and then read its properties for filling a spreadsheet.
I do not have knowledge of VBA and I have researched stack overflow but can not get it working. Basically I want to save all attachments (csv files) that are moved by rule to my folder 'Test' in outlook and save in my Documents.
The rule move emails with attachments.
When I set up the rule I do not have the option to use a macro as a rule (company requirements).
Please help!
You could create a rule, refer to this link:
How To Automatically Download/Save Attachments From Outlook To A Certain Folder?
sSaveFolder = "C:\Users\DT168\Documents\outlook-attachments\"
This vba code is means where you want to save attachment. You could change this to your Documents folder URL.
When I take a snippet or screenshot of something I'm working on and need to send it in an e-mail (MS Outlook), I don't always want to paste it in-line in the HTML body of the e-mail. There are times where I would like to add the image as an attachment.
In the interest of making this repetitive task a bit more efficient, is it possible for me to accomplish this without having to first save the image/screenshot and add an attachment manually? Perhaps a macro to convert an in-line image in my e-mail to an attachment on the same e-mail?
Downloading add-ons or plugin-ins is a no go; I work in a large corporate environment where this is near impossible to do.
Thank you!
What exactly do you mean by inline images? Images hosted on the remote HTTP servers and referenced by the HTML body? Or embedded image attachment referenced by the HTML body by their cid's? In the latter case, the attachments are already in the MailItem.Attachments collection.
You cannot simply convert an inline (embedded image) image into an attachment, you will need to save the inline attachment to a folder location, delete the inline attachment, and reattach the saved attachment.
I am trying to attach an Outlook message to a Word document entirely using VBA. I have been able to attach an Outlook Message to another Outlook Message. I am having problems attaching the Outlook Message to a Word Doc. I tried saving the Outlook Message to the drive using:
message.SaveAs "C:/temp/file.msg", olMSG
But it won't save the file.
I also tried recording a macro to see how Word would attach the file, but Word does not record macros for drag and drop from the Outlook Drafts Folder.
The Word object model doesn't provide any property or method for attaching files.
But it won't save the file.
Could you please be more specific? Do you get any exception in the code?
Anyway, I'd recommend choosing another folder/drive for saving messages. The C: drive requires admin privileges on latest OS.
I had needed to get the attachments from an email draft so that I could check if they were an Excel file, and if so read through the file to copy/paste a range of certain text into the body of the email.
Thanks to an answer from my previous question I've figured out how to get the email attachments.
I'm working on how to get when an attachment is added to that specific email draft, but the more pressing issue is that once I've added something, how do I open it in Excel?
Dim NewMail As MailItem, oInspector As Inspector
Set oInspector = Application.ActiveInspector
Dim eAttachment As Object
'~~> Get the current open item
Set NewMail = oInspector.CurrentItem
Set eAttachment = CreateObject("Excel.Application")
With eAttachment
' Change file name to suit
.Workbooks.Open FileName:=NewMail.Attachments.Item(1).FileName
End With
This tells me that the file doesn't exist. So I look at the pathName on the attachment and find that it is set to nothing. There is no text there.
I'm thinking this has something to do with the Excel file being attached is on a computer networked to the one I am using.
I've searched, but "get contents of outlook email attachment on networked computer" didn't net me the results I wanted.
How would I gain access to the workbooks of the attached Excel file? Please note my example only uses the first attachment because for testing I am only attaching the one Excel file. When I can get the Excel file to open I will check the attachments to ensure they are excel files before I open them.
Edit: I just copied the file over to my local hard drive and tried to open the file, same issue. Am I going to have to open the file temporarily to open it? Is that what Outlook does when you edit an email attachment?
In case someone has the same issue I did - Here's what I've come to the conclusion of:
the PathName object, perhaps it is just the version of outlook that I am using, but it stores absolutely nothing. I tested it out on both of the computers in my office and my one at home, with the same result: it is just not there. Each Attachment object will have a SaveAsFile method that you can use to save the file to the temporary folder and access it from there via the usual Excel applications. This seems to be the only way, unfortunately, to read through the contents of a file attachment, even when it is simply a draft copy you are writing.
Also, what got me was the fact that I was trying, in the Excel file, to find the last cell in use, and was using the .End(xlUp) method. Remember, if you are using constants defined in the program you use, it is not defined in another. E.G. I was opening this Excel file from Outlook, technically, so trying to use xlUp gave me errors. Simply open up Excel, Word, or what have you to check the value of such constants and set them in your program.