1

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
Community
  • 1
  • 1
user791411
  • 149
  • 12
  • What's different about the output from `Parse_Resource` between the working and non-working machines? Anything? If you take the path and paste it into Windows Explorer can it be accessed? – Tim Williams Jul 14 '14 at 16:16
  • Hi Tim! The same SharePoint path can be accessed within Internet Explorer in the non-working machine, just **not** when it's running in the script. Does this help? – user791411 Jul 15 '14 at 00:41
  • The same WebDAV path, or the same http path? Ie. Are you talking about accessing the path output from `parse_Resource`, or an HTTP path? – Tim Williams Jul 15 '14 at 03:08
  • 1
    I'm having a similar problem whereby XL can't see the webdav path and throws a "file not found" UNLESS the user has already accessed the Sharepoint resource via another route before running my VBA (e.g. by viewing it in Windows Explorer, or by saving/loading a file to/from it). Just curious if you ever found a solution? – blackworx Feb 20 '15 at 09:10

0 Answers0