Been using code below for years. It creates new folder, and names it to next work-day's date + adds another folder within this, named "VO". Code got two "fPath"-lines. The one at pause is the original one. With this one I can move my files around, and code will still create new folder, based on location of ThisWorkbook.
However, with OneDrive, original "fPath"-line ends in "Run-time error 52: Bad file name or number", marking line .CreateFolder (EndDir1)
.
Why doesn't this code work in OneDrive? When I change "fPath"-line into complete address, it works just fine.
Sub NewFolderNextWorkDay()
Dim FSO As Object
Dim fsoObj As Object
Dim NeArbDg As Double
NeArbDg = Application.WorkDay(Date, 1)
Dim Dato As String
Dim fPath As String
Dim EndDir1, EndDir2 As String
Dato = Format(NeArbDg, "yyyy-mm-dd")
'fPath = ThisWorkbook.Path & "\..\" '(old code, worked fine until OneDrive came along)
fPath = "C:\Users\MyId\OneDrive - MyJob\Mine dokumenter\PROD\TEST\2022\" '(new code, works ok with OneDrive)
EndDir1 = (fPath & Dato & "\")
EndDir2 = (fPath & Dato & "\VO")
Set fsoObj = CreateObject("Scripting.FileSystemObject")
With fsoObj
If Not .FolderExists(EndDir1) Then
.CreateFolder (EndDir1)
End If
If Not .FolderExists(EndDir2) Then
.CreateFolder (EndDir2)
End If
End With
End Sub