How to handle errors when loading a Sharepoint file?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
I can't seem to catch the error when attempting to load a file from Sharepoint. If the file doesn't exist it pops up with the error:

1675856143082.png
1675856155275.png


1675856176235.png


My code:
VBA Code:
Sub Test1()
    Dim WB1 As Workbook, ActiveListWB As Workbook
    Dim WS1 As Worksheet, WS2 As Worksheet
    Dim WeekFolder As String
    
    Set WB1 = ThisWorkbook
    Set WS1 = WB1.Sheets("1")
    Set WS2 = WB1.Sheets("2")

    SharepointFolder = "https://xxxxxxx.sharepoint.com/Testfolder/"
    SubFolder = "WC_" & Format(Range("B3"), "YYYYMMDD") & "/"

    'MONDAY
    MyFile = SharepointFolder & SubFolder & WS1.Range("D7") & ".csv"
    
    Set ActiveListWB = Workbooks.Open(MyFile, ReadOnly:=True)
    WS2.Range("A1:D2000").Value2 = ActiveListWB.Sheets(1).Range("A1:D2000").Value2
    ActiveListWB.Close False
    WB1.Activate
    
End Sub

is there a way to catch that error?

Appreciate any help
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Edit:
I can prevent the 1st error with disable alerts but I still get the runtime error
 
Last edited:
Upvote 0

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