0

I want to run the below VBA to create a new folder within the folder where the current file is stored.
So far I have done this using the following simple VBA:

Sub Create_Folder()
MkDir Application.ThisWorkbook.Path & "\New Folder"
End Sub

Now, my company moved to sharepoint and when I run this VBA within a sharepoint folder I get runtime error 76.
I assume this is caused because ThisWorkbook.Path can not correctly identify the path anymore.
Therefore, I checked how the path looks like:

https://company.sharepoint.com/sites/Finance1/Freigegebene Dokumente/Controlling/

In order to use this path I adjusted it in the VBA:

Sub Create_Folder()
WorkbookPath = ThisWorkbook.Path
WorkbookPath = "\\" & Replace(Split(WorkbookPath, "//")(1), "/", "\")
MkDir WorkbookPath & "\New Folder"
End Sub

However, I am still getting runtime error 76 when I try to create the new folder.


What is strange to me is that when I check the link in the windows explorer it loosk totally different to the link that I get with Application.ThisWorkbook.Path.

C:\Users\firstname.lastname\company\Controlling - Dokumente

Do you have any idea how I can solve this issue and create a new folder in the same folder where the current file is stored?

Michi
  • 4,663
  • 6
  • 33
  • 83
  • Is this file in a synced folder? – Ricardo Diaz Feb 01 '21 at 13:35
  • Not sure but in the explorer it has the status column with the cloud- or check-sign next to it. I assume this means that it is a synced folder. – Michi Feb 01 '21 at 13:39
  • Check my answer here on how to get the local path of a sharepoint folder: https://stackoverflow.com/a/65605893/1521579 – Ricardo Diaz Feb 01 '21 at 13:41
  • This problem (converting a OneDrive web path to the local path of the synced folder) now has a more reliable solution [here](https://stackoverflow.com/a/73577057/12287457). – GWD Sep 06 '22 at 00:04

0 Answers0