SharePoint Map

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all

I've been using the following code from a previous project

VBA Code:
Sub DownloadListFromSharepoint() 'This sub checks the Sharepoint folder for files and puts the filename in A1 of Sheet3

    Dim SharepointAddress As String
    Dim LocalAddress As String
    Dim objFolder As Object
    Dim objNet As Object
    Dim objFile As Object
    Dim FS As Object
    Dim rng As Range
    
    SharepointAddress = "https://URLOfDoom"

    Set objNet = CreateObject("WScript.Network")
    Set FS = CreateObject("Scripting.FileSystemObject")
    objNet.MapNetworkDrive "Y:", SharepointAddress
    
    Set objFolder = FS.getfolder("Y:")
    
    Set rng = ThisWorkbook.Worksheets(2).Range("A1")
    GetAllFilesFolders rng, objFolder, "" & strSharepointAddress
    objNet.RemoveNetworkDrive "Y:"
    Set objNet = Nothing
    Set FS = Nothing

End Sub

Public Sub GetAllFilesFolders(rng As Range, ObjSubFolder As Object, strSharepointAddress As String)

    Dim objFolder As Object
    Dim objFile As Object
    
    For Each objFile In ObjSubFolder.Files
        rng.Offset(0, 0) = objFile.Name
        Set rng = rng.Offset(1, 0)
    Next
    
End Sub

It does exactly what the comment says - checks a folder (which only ever has one file in it at a time - but this file has a variable name) and puts the file name in A1 of Sheet3. Later another bit of code checks the value of A1 to complete a string and import the .txt file (the one file in the folder is always .txt afaik).

The code works well in the old project because there were multiple files (with names that changed) in the folder searched and I needed a list of those files on the sheet - with this project I don't - I just need the one. But this bit of code is a little beyond my scope - instead of assigning the file name to a cell, how can I just add it to a new variable?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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