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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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