Outlook Folder with MSG Files, transfer to a CSV - vba

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.

Related

how to run Acrobat Create New PDF or Convert to PDF using VBA in Outlook desktop version

We have a process where the user saves an email as a .pdf file. I have developed a script that pulls the information for the filename from the email and prompts the user for additional necessary information.
What I can't figure out is how to then have my VBA script select the appropriate Acrobat command in the Ribbon or right-click menu. I've tried executemso, but the msoid is a non-specific "CustomControl". Specifically, the Acrobat add-in adds another tab to the Ribbon called "Acrobat" which then has the option Selected Messages (dropdown) with Create New PDF. Typically, my users just right click the email and choose "Convert to Adobe PDF". A third option would be to programmatically select File | Save as Adobe PDF.
So ideally a user could select an email message and run my VBA macro and that macro would then continue the process to the convert to pdf. Another thought I've had is to somehow watch for the event of creating a pdf and to run the macro and copy the programmatically-created filename to the clipboard.
There is no trivial way to execute custom ribbon controls from other add-ins. You may consider contacting add-in developers for any public API in the add-in which you could call directly. Also you may take a look at the Accessibility API.
Instead, you can try using the Word object model for saving email as a PDF file on the disk. The Inspector.WordEditor property returns the Microsoft Word Document Object Model of the message being displayed. The Document.ExportAsFixedFormat2 method allows saving a document which represents the message body in PDF or XPS format.

Using VBA to save an attachment as a different filetype

I'm trying to write a macro to save html attachments as .txt files (and then do some stuff with the .txt file) but am running into a problem right out of the gate - the Attachment object only has the SaveAsFile method, not the SaveAs method, and the SaveAsFile method only has the path parameter, not the type parameter.
I've tried various methods of just sneaking .txt into the pathname, and none have worked.
This is my first attempt at "serious" programming, so it's possible I'm missing something incredibly obvious.
You just need to specify the desired extension for the file. The SaveAsFile method of the Attachment class saves the attachment to the specified path (with the specified filename).
You may also find the Getting Started with VBA in Outlook 2010 article helpful.

Saving an Outlook Message using VBA

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.

Getting contents of Outlook email attachment from networked computer

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.

generating an html attachment vb.net

I am trying to generate a report html file and email it as an attachment with vb.net
I know how send mail and attachments.
Do I need to generate the html file, save it as an .html file to the local disk where the program runs, then add its file path to the attachment property to send it to the recipient?
It is going to be a rather large report, and I would like to send it as an attachment instead of directly inside of the email itself.
Thanks
Yes, you save the file to disk ant then add to the Attactments collection of the MailMessage. Here is the C# syntax to create an Attachment from a file on disk and add the attachment to the message. It will be similar for VB.Net.
Attachment att = new Attachment(filename);
message.Attachments.Add(att);