I am trying to create a macro based VBA wherein the code will access sharepoint files do some file moving, copying as well as some data manipulation activities. While using UNC path for sharepoint folder, at times it works and sometimes it throws Runtime error 76: path not found.
The part of code where error is occuring is as follows:
Sub ConvertXLSBtoXLSX()
Dim SharePointPath As String
Dim SharePointFile As String
Dim folder As Object
Dim file As Object
Dim foundFile As Boolean
Dim oldFilePath As String
Dim newFilePath As String
Dim FSO As New FileSystemObject
Call AskForDate
' Specify the SharePoint file path and filename
SharePointPath = "https://sites.xyz.com/sites/ABC/Shared Documents/Employee/"
SharePointFile = "Data.xlsb"
SharePointFolderPath = "\\sites.xyz.com@SSL\DavWWWRoot\sites\ABC\Shared Documents\Employee\"
Const fileExtension As String = ".xlsb"
Set folder = CreateObject("Scripting.FileSystemObject").GetFolder(SharePointFolderPath)
For Each file In folder.Files
If UCase(Right(file.Name, Len(fileExtension))) = UCase(fileExtension) Then
oldFilePath = file.Path
newFilePath = Left(oldFilePath, InStrRev(oldFilePath, "\")) & SharePointFile
' Rename the file
Name oldFilePath As newFilePath
foundFile = True
Exit For
End If
Next file
End Sub
If I open the sharepoint path in file explorer mode and run the code, it will work perfectly. This looks like some connection is getting disconnected in a day or at a frequency and me opening the driver in file explorer mode is enabling the connection.
Is there anyway I can make this automated such that I don't need to do this all the time manually?