Hi there I'm new to macros and I'm having some trouble with this error 52 coming up every time I hit run, it does occur if I end my one drive I don't know why this is happening any help is appreciated.
Attachment 675379
Hi there I'm new to macros and I'm having some trouble with this error 52 coming up every time I hit run, it does occur if I end my one drive I don't know why this is happening any help is appreciated.
Attachment 675379
If your Workbook is stored on OneDrive, ThisWorkbook.Path will return something that starts with "https://" to signify the OneDrive location and you can't create new folders in OneDrive using the FileSystemObject. Here's a function adapted from this thread:
https://stackoverflow.com/questions/...-with-onedrive
You could then try re-coding as:![]()
Public Function LocalFullName$(ByVal fullPath$) 'Finds local path for a OneDrive file URL, using environment variables of OneDrive 'Reference https://stackoverflow.com/questions/33734706/excels-fullname-property-with-onedrive 'Authors: Philip Swannell 2019-01-14, MatChrupczalski 2019-05-19, Horoman 2020-03-29, P.G.Schild 2020-04-02 Dim ii& Dim iPos& Dim oneDrivePath$ Dim endFilePath$ Dim jj& If Left(fullPath, 8) = "https://" Then 'Possibly a OneDrive URL jj = 1 If InStr(1, fullPath, "my.sharepoint.com") <> 0 Then 'Commercial OneDrive 'For commercial OneDrive, path looks like "https://companyName-my.sharepoint.com/personal/userName_domain_com/Documents" & file.FullName) 'Find "/Documents" in string and replace everything before the end with OneDrive local path iPos = InStr(1, fullPath, "/Documents") + Len("/Documents") 'find "/Documents" position in file URL endFilePath = Mid(fullPath, iPos) 'Get the ending file path without pointer in OneDrive. Include leading "/" Else 'Personal OneDrive 'For personal OneDrive, path looks like "https://d.docs.live.net/d7bbaa#######1/" & file.FullName 'We can get local file path by replacing "https.." up to the 4th slash, with the OneDrive local path obtained from registry iPos = 8 'Last slash in https:// For ii = 1 To 2 iPos = InStr(iPos + 1, fullPath, "/") 'find 4th slash Next ii endFilePath = Mid(fullPath, iPos) 'Get the ending file path without OneDrive root. Include leading "/" jj = 2 End If endFilePath = Replace(endFilePath, "/", Application.PathSeparator) 'Replace forward slashes with back slashes (URL type to Windows type) For ii = jj To 3 'Loop to see if the tentative LocalWorkbookName is the name of a file that actually exists, if so return the name oneDrivePath = Environ(Choose(ii, "OneDriveCommercial", "OneDriveConsumer", "OneDrive")) 'Check possible local paths. "OneDrive" should be the last one If 0 < Len(oneDrivePath) Then LocalFullName = oneDrivePath & endFilePath Exit Function 'Success (i.e. found the correct Environ parameter) End If Next ii 'Possibly raise an error here when attempt to convert to a local file name fails - e.g. for "shared with me" files LocalFullName = vbNullString Else LocalFullName = fullPath End If End Function
WBD![]()
If fso.FolderExists(LocalFullName(ThisWorkbook.Path) & "\Logs\") = False Then fso.CreateFolder LocalFullName(ThisWorkbook.Path) & "\Logs\" End If
Office 365 on Windows 11, looking for ✶ rep!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks