macro save attachments from outlook to share point error

rurounisena

New Member
Joined
Apr 13, 2018
Messages
7
When I run my code I get run time error 2147024843 and says it cannot save attachment. Can anyone help? Below is my code with debug in blue.

Sub SaveAttachmenttoSharePoint()


'Declaration
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim myName As String


'Ask for destination folder
myOrt = "\\https://hub.cscinfo.com/teams/Lms/LmsCompliance/Canada%20ARR/Forms/AllItems.aspx"


'Work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection


'For all items do...
For Each myItem In myOlSel


'Point to attachments
Set myAttachments = myItem.Attachments


'If there are some...
If myAttachments.Count > 0 Then



'For all attachments do...
For i = 1 To myAttachments.Count


'Save them to destination
myName = myAttachments(i).DisplayName
myName = Replace(myName, "&", "_")
myName = Replace(myName, "/", "-")
myName = Replace(myName, "", "_")
myName = Replace(myName, ":", "_")
myName = Replace(myName, "?", "_")
myName = Replace(myName, Chr(34), "_")
myName = Replace(myName, "<", "_")
myName = Replace(myName, ">", "_")
myName = Replace(myName, "|", "_")
myAttachments(i).SaveAsFile myOrt & _
myName







Next i





End If

Next


'Release variables
Set myItems = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
Set myAttachment = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top