I'm accessing a customer's SharePoint through VBA using the Microsoft Scriptime Runtime in order to pull data from the Excel workbooks stored in a bunch of SharePoint directories with the following Sub
and Function
.
For some reason, my Sub
on my local machine (which is logged into the SharePoint) works perfectly, but on other peoples' machines, fails to find the path at the last line:
Set trackerFolder = fs.GetFolder(Parse_Resource(baseDir & trackExtension))
For reference, the Excel file is stored on a network drive separate from the customer SharePoint.
Does anyone have any ideas as to why the directory does not populate when the macro is run on another colleague's machine, but works when run on my own? Thanks in advance for the help!
Here is the sub (and my apologies for declaring variables all on the same line):
Sub pullData()
Dim folder, trackerFolder As folder
Dim Fnum As Long
Dim f, trackF As File
Dim fs As New FileSystemObject
Dim FSO As Scripting.FileSystemObject
Dim folder2 As Scripting.folder
Dim file2 As Scripting.File
Dim trackExtension, appExtension, baseDir, FilesInPath, MyFiles(), array_example(), workbookName, trackerName As String
Dim i, folderNameInt As Integer
Dim folderNames As Variant
Dim mybook, trackerBook As Workbook
Dim sh, shtrackerAppDataEntry As Worksheet
Dim ErrorYes As Boolean
Dim intAppRow, totalScriptNum, scratchVar As Integer
'Set counter
i = 1
'Name of tracking document
trackerName = "Document Latest Macro.xlsm"
'Fill in with all app names, make sure it matches rows in Application Testing Data Entry
'At some point, fill in with app names from Config
'Must match SharePoint app structure
folderNames = Array("Folder 1", "Folder 2")
'At some point, put in Config tab the SharePoint file structure
appExtension = "Big Dir 1/Big Dir 2/"
'Ditto above
baseDir = "https://WEBSITE.sharepoint.com/Integration/Shared Documents/"
'Ditto above
trackExtension = "Project Management/"
'Basic Stuff
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
'Setting variables for tracker book
Set trackerFolder = fs.GetFolder(Parse_Resource(baseDir & trackExtension))
The function PARSE_RESOURCE
is one I found from another post (here: Open an Excel file from SharePoint site):
Public Function Parse_Resource(URL As String)
'Uncomment the below line to test locally without calling the function & remove argument above
'Dim URL As String
Dim SplitURL() As String
Dim i As Integer
Dim WebDAVURI As String
'Check for a double forward slash in the resource path. This will indicate a URL
If Not InStr(1, URL, "//", vbBinaryCompare) = 0 Then
'Split the URL into an array so it can be analyzed & reused
SplitURL = Split(URL, "/", , vbBinaryCompare)
'URL has been found so prep the WebDAVURI string
WebDAVURI = "\\"
'Check if the URL is secure
If SplitURL(0) = "https:" Then
'The code iterates through the array excluding unneeded components of the URL
For i = 0 To UBound(SplitURL)
If Not SplitURL(i) = "" Then
Select Case i
Case 0
'Do nothing because we do not need the HTTPS element
Case 1
'Do nothing because this array slot is empty
Case 2
'This should be the root URL of the site. Add @ssl to the WebDAVURI
WebDAVURI = WebDAVURI & SplitURL(i) & "@ssl"
Case Else
'Append URI components and build string
WebDAVURI = WebDAVURI & "\" & SplitURL(i)
End Select
End If
Next i
Else
'URL is not secure
For i = 0 To UBound(SplitURL)
'The code iterates through the array excluding unneeded components of the URL
If Not SplitURL(i) = "" Then
Select Case i
Case 0
'Do nothing because we do not need the HTTPS element
Case 1
'Do nothing because this array slot is empty
Case 2
'This should be the root URL of the site. Does not require an additional slash
WebDAVURI = WebDAVURI & SplitURL(i)
Case Else
'Append URI components and build string
WebDAVURI = WebDAVURI & "\" & SplitURL(i)
End Select
End If
Next i
End If
'Set the Parse_Resource value to WebDAVURI
Parse_Resource = WebDAVURI
Else
'There was no double forward slash so return system path as is
Parse_Resource = URL
End If
End Function