VBA Outlook将MailItem保存在SharepointOnline中

huangapple go评论64阅读模式
英文:

VBA Outlook save MailItem in SharepointOnline

问题

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

英文:

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

答案1

得分: 1

Outlook的MailItem.SaveAs只能处理文件路径,无法处理HTTP服务器。

一般来说,如果你可以在Windows资源管理器中打开目标文件夹,并且拥有写入权限,那么你应该能够使用MailItem.SaveAs

英文:

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.

答案2

得分: 0

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

As a workaround, I created a shortcut of the folder in SharePoint to my OneDrive:

VBA Outlook将MailItem保存在SharepointOnline中

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

VBA Outlook将MailItem保存在SharepointOnline中

英文:

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:
VBA Outlook将MailItem保存在SharepointOnline中

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

VBA Outlook将MailItem保存在SharepointOnline中

huangapple
  • 本文由 发表于 2023年4月4日 06:34:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924214.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定