vba excel what is the path for folder creation in Sharepoint

Georgem106

New Member
Joined
Jun 12, 2015
Messages
7
Hi. I had to move my Excel Workbook to be incorporated with SharePoint. I have the excel vba code listed below and I copied the link to the SharePoint Library where the main folder xxxxx Document Files, exists.
When I execute the vba, I get the error shown in the attached image.
After numerous searches and changes, I am still getting the error.
Using an Immediate window, the path is created correctly but when it hits Sharepoint for the folder creation, it errors out.
Another Sub will open the existing folder, that was dropped into SharePoint, so the communication exists.
Could it be some SharePoint permission thing since vba is involved, or what am I missing in the code?
Any help will be greatly appreciated.

Sub MakeMyFolder()

Dim fdObj As Object
Dim C As String
Dim P As String
Dim File As String
Application.ScreenUpdating = False
C = Left(Data_UF.Txt_Case_Number.Text, 10)
P = ("https://xxxxxx.sharepoint.com/sites/xxxxx/xxx xxxxx/xxxxx Document Files/" & C)

File = P & C
Set fdObj = CreateObject("Scripting.FileSystemObject")
If fdObj.FolderExists(File) Then
MsgBox "Folder Already Exists.", vbInformation, "Folder Exists"
Else
'Debug.Print File
fdObj.CreateFolder (File)
MsgBox "Folder has been Created.", vbInformation, "Folder Created"
End If
Application.ScreenUpdating = True

End Sub

Error1.jpg
Error2.jpg
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If you are using a HTTP web address, you need to pay attention to URL Encoding. Quote from the link:
One of the most common special characters is a white space. You can't type a space in a URL directly. A space position in the character set is 20 hexadecimals. So you can use %20 in place of a space when passing your request to the server.

If you open a file saved in SharePoint and press File → Info → Copy Path, the URL it gives you will be a good template to start from.
 
Upvote 0
This worked for me. Thanks to Josh.
Hopefully it will help others looking for this solution.

P = Environ$("USERPROFILE") & "\xxxx\xxxx xxxx - xxxx xxxxxx\xxxx xxxx xxxx\"
 
Upvote 0
Solution
If you are using a HTTP web address, you need to pay attention to URL Encoding. Quote from the link:


If you open a file saved in SharePoint and press File → Info → Copy Path, the URL it gives you will be a good template to start from.
Thanks for your input. I tried all that and more. It did not work. Thank you though. I did fiind the solution.
 
Upvote 0
I've had the same trouble & tried to implement the solution above. I've looked everywhere for a solution to no avail.
Here's the code involved..
VBA Code:
Private Sub Save_File_Click()
'
'
Dim statements
'
Req_Path = Environ$("userprofile") & "\\SharePoint\###\#######\Requisitions"
Set CurrentYearFolderPath = CreateObject("Scripting.FileSystemObject")
J = 0
Auto_Fill = False
    'check that a file folder named for the current year exists:
If Not CurrentYearFolderPath.FolderExists(Req_Path & "\" & VBA.Year(VBA.Date)) Then 'Create a new directory for the current year
    CurrentYearFolderPath.CreateFolder (Req_Path & "\" & VBA.Year(VBA.Date))
    MsgBox "A new directory in the requisitions folder has been created for this year", vbOKOnly + vbInformation, "### Expenses"
End If

It doesn't throw any errors; the problem arises with the "IF" statement. The code isn't recognizing the folder in the given path does indeed already exist, so instead of skipping to the "END IF", it steps to the createfolder statement.
It's like I'm missing some reference being enabled, but I didn't see any listed that looked likely. BTW - I do have WEBDAV enabled on this workstation as well as the M/S Scripting Runtime reference.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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