Outlook 2016 Attachment SaveAsFile Exception

Add-in Express™ Support Service
That's what is more important than anything else

Outlook 2016 Attachment SaveAsFile Exception
Calling SaveAsFile on a mail attachment raises an exception. 
Eugen Wiest




Posts: 4
Joined: 2016-07-27
Hello,

when calling the SaveAsFile method on a mail attachment, an exception with the following message is thrown: "Falscher Variablentyp" (en: ~ incorrect variable type)

This problem only occurs under Outlook 2016. Under Outlook 2013 the attachment could be saved.

EMail.Attachments(i).SaveAsFile('C:\Users\<my-user-name>\AppData\Roaming\MyCompany\MyApp\MyFolder\' + EMail.Attachments(i).FileName);


Best regards,

Stefan Beer
Posted 27 Jul, 2016 03:16:36 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Hello Stefan,

I suppose the problem relates to the Email variable or to some other part of the statement, not to saving the attachment. I suggest that you split the statement introducing temp variables to keep the intermediate results and debug this code fragment to find the source of the error.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Jul, 2016 04:06:34 Top
ratio




Posts: 4
Joined: 2016-07-27
Introducing variables indeed solved the problem:


...

var
  Attachment: OleVariant;
  TempPath: string;

...

  Attachment := EMail.Attachments(i);
  TempPath := <MY-FOLDER-PATH> + Attachment.FileName;
  Attachment.SaveAsFile(TempPath);

...


I don't understand why it solves the problem, but ok...

Thank you!
Posted 27 Jul, 2016 04:54:18 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 27 Jul, 2016 06:25:31 Top