0

I have to adapt a Macro which is saving the current MailItem Selected in differents folders on Sharepoint Online site of my company: On Manual way we are well able to do SaveAs, and add the .msg file to Sharepoint folder by entering the URL of Sharepoint in the Address bar.

The idea is to have a macro like that:

'for each mail selected (but generally there is only one mail selected):
For Each olkMsg In Outlook.ActiveExplorer.Selection
'Many actions done to collect information from mail

'Save the email in Sharepoint 
olkMsg.SaveAs "https://MyCompany.sharepoint.com/sites/MyTeam/Shared Documents/TestArchives/TestXXX.msg", olMSG

I tried by encoding the URL (It made disappeared the run time error -2147286788 (800300fc) but nothing is going to Sharepoint:

olkMsg.SaveAs "https%3A%2F%2FMyCompany.sharepoint.com%2Fsites%2FMyTeam%2FShared Documents%2FTestArchives%2FTestXXX.msg", olMSG

I tried the UNC path, it same to do not work on our Sharepoint on Microsoft Cloud:

olkMsg.SaveAs "\\MyCompany.sharepoint.com\sites\MyTeam\Shared Documents\TestArchives\TestXXX.msg", olMSG

I started to check if there is a way to add the file with ADODB.Recorset, but I'm completly lost if it can be a solution.

And on Internet, I'm just able to find solution to save Excel file on Sharepoint... I don't mind to have to proceed through an intermediate step as save file on a Temp file first and then transfer it to Sharepoint ( I tried as well without success, and I deleted the code I wrote...)

Thanks

Renaud
  • 2,709
  • 2
  • 9
  • 24

2 Answers2

1

Outlook's MailItem.SaveAs can only work with file paths, it does not deal with HTTP servers.

As a rule of thumb, if you can open the target folder in Windows Explorer, you should be able to use MailItem.SaveAs as long as you have write access.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks for answer. I didn't manage to save directly to sharepoint with MailItem.SaveAs. And don't know why it work when we do a manual SaveAs and paste the URL... Unfortunately MailItem.SaveAs is totally differents of WorkBook.SaveAs (which works fine with HTTP URL). I found a workaround by creating a shortcut of folder in Sharepoint to myOneDrive and then put the path of this shortcut in mailItem.SaveAs (C:\Users\USERID\OneDrive - MyCompany\FolderNameInSharepoint) – Renaud Apr 04 '23 at 08:22
0

I didn't manage to save directly to sharepoint with MailItem.SaveAs. And don't know why it work when we do a manual SaveAs and paste the URL... Unfortunately MailItem.SaveAs is totally differents of WorkBook.SaveAs (which works fine with HTTP URL).

As workaround I created a shortcut of folder in Sharepoint to my OneDrive: enter image description here

and then put the path of this shortcut in mailItem.SaveAs "C:\Users\USERID\OneDrive - MyCompany\FolderNameInSharepoint"

enter image description here

Renaud
  • 2,709
  • 2
  • 9
  • 24