Consulting

Results 1 to 6 of 6

Thread: Bad file name or number - Runtime Error 52

  1. #1
    VBAX Regular
    Joined
    Mar 2017
    Posts
    6
    Location

    Bad file name or number - Runtime Error 52

    I'm using a DIR function to check the existence of asaved file in Sharepoint, but each variation of strFilename used: strFilename = <My URL> & ShrtNamestrFilename = "//teamportalprod1.xxx.org/sites/RCSvcsInfo/RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName strFileExists = Dir(strFilename, vbDirectory)returns a runtime error 52 - "Bad file name ornumber" I am able to save the file using <URL> & ShrtName

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Sufficient:

    strFileExists = Dir(strFilename)

  3. #3
    VBAX Regular
    Joined
    Mar 2017
    Posts
    6
    Location
    I just caught an article mentioning that DIR() using the URL will not work, which only leaves me
    //teamportalprod1.xxx.org/sites/RCSvcsInfo/RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName as my option. Note taken that vbDirectory is not required, but still receive
    runtime error 52 - "Bad file name or number".

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    vbDirectory is wrong if you are looking for a file.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Don't have SharePoint anymore. but you can try


    bFilexists = Dir ("//teamportalprod1.xxx.org/sites/RCSvcsInfo/RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName) <> 0
    

    or

    bFilexists = Dir ("\\teamportalprod1.xxx.org\sites\RCSvcsInfo\RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName) <> 0
    


    This post reportedly has a solution, at least for SP2013


    https://social.technet.microsoft.com...repointgeneral
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    Mar 2017
    Posts
    6
    Location
    I tried both of your suggestions, each receiving the same "Bad file name or number". I also tried the following code from social.technet.microsoft.com...repointgeneral

    Public Function FileExist(SharePointURL As String) As Boolean
    ' This function check URL exist
    ' It return true if file exist in sharepoint
    ' SharePointURL include file extension' IMPORTANT:You need to activate reference "Microsoft WinHTTP Services. version 5.1"!!!!!
    Dim RequestSharepoint As New WinHttpRequest
    On Error GoTo FileExistError
        RequestSharepoint.Open "HEAD", SharePointURL
        RequestSharepoint.Send
        If RequestSharepoint.Status = 200 Then
            FileExist = True
        Else
            FileExist = False
        End If
        Exit Function
    FileExistError:
        FileExist = False
    End Function


    I passed my URL string and added WinHTTP Services.
    This time the RequestSharepoint.Status was a 401; Unauthorized.
    I'm starting to believe this issues is more related to administrative rights.
    So, I wonder why myself and others are able to straight out able to save the file in SharePoint, but need to be authenticated first, just to verify a file existence.

Posting Permissions

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