Creating new Folder in Sharepoint directory using VBA Excel

Sagar0650

Board Regular
Joined
Nov 25, 2019
Messages
55
Office Version
  1. 2019
Platform
  1. Windows
I am trying to create the new folder on sharepoint using Mkdir but it is not working.
is there any other way of doing it?
Thanks in advance for help
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Do you have the SharePoint folder(s) synced to your computer? What exactly is not working? Do you get errors? What do they say? What is the code you have been using? For the best chance for an answer, please provide as much information as is relevant.
 
Upvote 0
This is the code, it's very simple 2 line of code where i just want to create the folder on sharepoint
VBA Code:
Sub crfolder()

    usrdt = Format(Date, "DD-MMMM-YYYY") & "-" & Format(Now(), "hh.mm AMPM") & "/"

        MkDir "//mysite.sharepoint.com/teams/test1/test2/" & usrdt
 
End Sub

this gives me an runtime error '76': Path not found
i have tried with both forward & back slash
 
Upvote 0
Yep - as far as I know you're not going to be able to create folders with MkDir using a web URL. Sync the SharePoint directory to your computer. You'll then end up with a path something like C:\Users\%UserName%\SharePointCompanyName\SharePoint\Folder\Path\ that is local to your computer that you can use with MkDir. As an example,

VBA Code:
Sub CreateSharePointDirectory()
    Dim folderPath As String
    Dim ans As String
    Dim userName As String
    userName = Replace(Application.userName, " ", ".")
    folderPath = "C:\Users\" & userName & "\SharePointCompanyName\SharePoint\Folder\Path\"
    If Dir(folderPath, vbDirectory) = vbNullString Then
        ans = MsgBox("Folder does not exist. Create?", vbYesNo)
        If ans = vbYes Then
            MkDir folderPath
        Else
            Exit Sub
        End If
    End If
End Sub
 
Upvote 0
Thank you for response but is there any way of creating folder on sharepoint, without syncing sharepoint to my computer.
maybe not using mkdir but with something different.
any suggestions around it would be appreciated.
 
Upvote 0
but is there any way of creating folder on sharepoint, without syncing sharepoint to my computer
I don't know if any of these will work as I have never tried them (as everything I need to work on is already synced), but a quick google search yields some possible directions to take.

Two of those answers seem to center around temporarily mapping the SharePoint directory to a drive letter (specifically the first and second links).
 
Upvote 0

Forum statistics

Threads
1,223,666
Messages
6,173,672
Members
452,527
Latest member
ineedexcelhelptoday

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