I'm trying to automatically save workbooks using VBA to a Sharepoint folder- which needs to be created first. Code I have below works ONLY for saving the file. The MkDir function returns a Run-time error 76: Path not found. I'm at a loss what causes this error, because the path before /txt DOES exist and I do have the right permissions to add new folders by hand. I have also tried replacing the current path with \ instead of /, but other than making the code significantly slower this has no effect. No "solutions" online have done the trick for me.
Any ideas?
MkDir "https://placeholder.sharepoint.com/teams/Services_NL/Shared Documents/txt"
DateAndTime = Left(Replace(Replace(Replace(Now, " ", "_"), ":", ""), "/", ""), Len(Replace(Replace(Replace(Now, " ", "_"), ":", ""), "/", "")) - 5)
ActiveWorkbook.SaveAs "https://placeholder.sharepoint.com/teams/Services_NL/Shared Documents/Export/" & ExportSheet & DateAndTime & ".txt", FileFormat:=xlTextWindows
I had tried all different combinations of forward slash and backslash, "https://"...etc. But I finally got the MkDir command to work using the following syntax:
MkDir "\\mysite.sharepoint.com\IS\Shared Documents\My Docs\" & "MyNewFolder"
Note: Replace any %20 (used by Sharepoint to substitute a blank space in the URL) with a blank space. Or better yet, copy the folder address directly from the Windows Explorer navigation bar and then add the backslash to the end of it.
Also, I believe its important to first test the ability of your environment (permissions or otherwise) by opening your Sharepoint directory folders within Windows Explorer and navigating through them as a test. If you can do this, then MKDir command should work because you've proven the file directory is accessible.
The "Open with Explorer" icon is found on the Library tab within Sharepoint (I'm using Office 365). I've found that in some Sharepoint environments I've worked with the Library tab is accessible by default, but in others it is hidden (only the Browse and Page tabs are viewable). In that case, I got the Library (and Files) tab to appear by navigating into a Sharepoint folder, highlighting a bunch of files, and then just right-clicking on the highlighted section without clicking on any of the flyout options. Odd behavior, but it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With