MS Outlook VBA to upload email attachment to a Sharepoint with authentication

好久不见. 提交于 2020-02-06 08:31:10

问题


I'm still sort of a beginner in using VBA and I've been trying to figure out how to upload a file via VBA in MS Outlook to a Sharepoint. I've tried mapping the Sharepoint to my Network Drive and such but to no avail.

My code is as follows:

Public Sub saveAttachSentDate(MItem As Outlook.MailItem)

Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
Dim file As String
Dim DateFormat As String

sSaveFolder = "(URL of the sharepoint along with the folder to save it on)"


For Each oAttachment In MItem.Attachments
DateFormat = Format(MItem.SentOn - 1, "mm.dd.yy ")
file = sSaveFolder & DateFormat & oAttachment.DisplayName
oAttachment.SaveAsFile sSaveFolder & DateFormat & oAttachment.DisplayName
Next

End Sub

My File Name is labelled like this: "[My Department] - (Client Name) Telephony Summary"

I always get this error

"Run-time error '2147024735 (800700a1)': Cannot save the attachment. File name or directory name is not valid."

I'm thinking that the probable cause is that the sharepoint I'm uploading to requires a username and password every time you access it. I tried another sharepoint using the same exact code that doesn't require login credentials and it works just fine. I can't seem to find a work-around and I'd appreciate any help!


回答1:


The path passed to the SaveAsFile method can't be represented by the URL string or network location. You need to specify a local folder from which you can start uploading files. The Outlook object model doesn't provide anything for uploading files to any web servers, so you will have to do that on your own. To get that working I'd recommend developing a COM add-in. For example, VSTO based add-ins are built on top of .net framework and can use BCL classes to deal with that. See Walkthrough: Create your first VSTO Add-in for Outlook to get started quickly.



来源:https://stackoverflow.com/questions/51155112/ms-outlook-vba-to-upload-email-attachment-to-a-sharepoint-with-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!