Saving an Outlook Message using VBA - 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.

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.

Outlook Folder with MSG Files, transfer to a CSV

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.

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.

Opening an Excel file attachment located in a Lotus Notes Database through VBA

I am trying to automate the opening of an excel file located in a jobs database within lotus notes. I have been able to open up a window in lotus notes using the url, but I can't open the file located there automatically as it is an attachment.
This is the vba code I am using to open the link:
Application.ActiveWorkbook.FollowHyperlink Address:="Notes://URL", NewWindow:=True
What is the proper way to do it?
You'll need to use VBA to access Lotus Notes via COM. Then you can get at the NotesEmbeddedObject, save it using the ExtractFile method, and then launch that saved copy.
An example of VBA using Notes COM API: http://www.vbafin.com/Lotus-Notes-VBA-code.php
There's a document on IBM's site that will help you get started:
How to use LotusScript classes with Visual Basic

Unable to open word file (MSWord 2007) when word automation program is running

In my application i am using word automation to get the text content from the file. It is working fine no issues. But at the instant when word automation is processing, if i open the word file, it is throwing a dialog with message (any file)
"This file is in use by another application or user.
(C:\User\xyz\AppData...\Normal.dotm)".
When I am closing the dialog, it is asking for save the file "normal.dotm"...template file.
This happens only in MSWord 2007 not in MSWord 2003. can any one tell the solution please.
This probably happens because one Word instance has locked Normal.dotm and your instance modifies it and tries to save it.
You can try to set the Saved property of your template to True. Try this: Application.NormalTemplate.Saved := True. Word will now think that changes to Normal.dotm are saved and should not try to save again.