none
VBA check if folder exist on sharepoint documnets library and if not than create it RRS feed

  • Question

  • Hi All,

    I want to create folder on sharepoint. I want to user excel vba code to check if folder exist and if not than create folder. I have tried below code but it gives me run time error 52: Bad file name or number


    Sub test()
    Dim SpPath As String
    dim strfoldername as string
    
    strfoldername= "Test"
    SpPath  = "\\pathtosharepoint.aspx#\Shared%20Documents\strfoldername"
    
    
     If Dir(SpPath, vbDirectory) = "" Then
            MkDir SpPath
     End If
     
     End Sub

    I have replace "/" with "\" but still code do not work.

    Thanks,

    Zav



    Friday, April 22, 2016 5:27 PM

All replies

  • SpPath = "\\pathtosharepoint.aspx#\Shared%20Documents\" & strfoldername

    Your code for the path concatenation is incorrect, and you might want to try using a space instead of %20
    Friday, April 22, 2016 5:49 PM
  • Below is the actual path i used but i am still getting Bad file name error.

    SpPath = "\\companynamemalletier.sharepoint.com\sites\Communities\GGG-Retail-Toolkit---Test\_layouts\15\start.aspx#\Shared Documents\Forms\AllItems.aspx\" & strfoldername
    
    

    Monday, April 25, 2016 1:07 PM
  • Hi Zav,

    This forum is used to discuss about Excel developing issue, your issue is more related with VBA.

    I try to research and make a test with checking if folder exist on sharepoint document, I think you could try the link below with drive mapping to sharepoint.

    # Get the content of a sharepoint folder with Excel VBA

    http://stackoverflow.com/questions/1344910/get-the-content-of-a-sharepoint-folder-with-excel-vba

    Best Regards,

    Edward

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites;
    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 26, 2016 5:35 AM
    Moderator