+ Reply to Thread
Results 1 to 2 of 2

Run-time error '52'

Hybrid View

pedro53 Run-time error '52' 04-30-2020, 12:02 PM
WideBoyDixon Re: Run-time error '52' 05-01-2020, 04:37 AM
  1. #1
    Registered User
    Join Date
    04-30-2020
    Location
    Boston
    MS-Off Ver
    365
    Posts
    20

    Run-time error '52'

    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

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Run-time error '52'

    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

    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
    You could then try re-coding as:

    If fso.FolderExists(LocalFullName(ThisWorkbook.Path) & "\Logs\") = False Then
        fso.CreateFolder LocalFullName(ThisWorkbook.Path) & "\Logs\"
    End If
    WBD
    Office 365 on Windows 11, looking for rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Error message: Run-Time error '1004 '; application-defined or object-defined error
    By Davasu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 06:52 AM
  2. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  3. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  4. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  5. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  6. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  7. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1