Sharepoint Network Map Code Conversion

Luke777

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

About a year ago I used the following code on a project...

VBA Code:
Sub DownloadListFromSharepoint()



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 = "sharepointURL..."



Set objNet = CreateObject("WScript.Network")

Set FS = CreateObject("Scripting.FileSystemObject")

objNet.MapNetworkDrive "Y:", SharepointAddress



Set objFolder = FS.getfolder("Y:")



Set Rng = ThisWorkbook.Worksheets("chonk").Range("M7")

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(1, 0) = objFile.Name

Set Rng = Rng.Offset(1, 0)

Next



End Sub

Which worked very nicely for what I wanted it to do at the time.

As you can see, it dumps the filename in M7 (actually M8 for some reason - there's only one file in the folder anyway so it really doesn't matter too much).

I've made a few attempts to convert the code so instead of the filename being dumped on the sheet, it creates a new variable instead which I can use elsewhere in the code - for example, opening the file in the folder. My attempts didn't work though unfortunately. Sad noise.

To be clear, I'm using this method because the file in question changes name a lot, which is obviously annoying when it comes to VBA

Thanks for any help! :)
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

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