Consulting

Results 1 to 3 of 3

Thread: Error 52: bad file name or number with OneDrive for Business

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    May 2021
    Posts
    1
    Location

    Question Error 52: bad file name or number with OneDrive for Business

    Hello,

    We have a piece of software which automatically generates Word files and populates data using VBA. Since moving to OneDrive for Business, we are not using the personal version of OneDrive, we get the error 'Error 52: Bad file name or number' when running reports.

    I have investigated and the issue happens when vba attempts to open another file, which is generated successfully in the same folder as the Word file. I believe the issue is that VBA can't decipher the online address of OneDrive that the code seems to get when referencing ActiveDocument.Path, I checked with msgbox(fieldNameFile). The format is 'https://<companyname>.sharepoint.com/personal/<username>/Documetns/Documents/SoftwareCompany'.

    I can get it to work if I change the fieldNameFile in VBA to the static local path of OneDrive i.e. 'C:\Users\<username>\OneDrive - <companyname>\Documents\SoftwareCompany'. Alternatively if I turn off collaboration in OneDrive VBA will attempt to load the local copy of the files in the same location as listed in the last sentence, which also works. To turn off collaboration in OneDrive go to Help & Settings > Settings, click the Office tab and deselect 'Use Office applications to sync Office files that I open'.

    Neither of these options is great as we can't ask users to edit every single report they open and they also need to collaboratively use files on OneDrive on a regular basis. Does anyone have any ideas?

    'populate the menu from the fields in ReportFields.txt
    fieldNameFile = ActiveDocument.Path + "\ReportFields.txt"
    
    'the next line is where it fails, so you don't really need the rest of the code
    Open fieldNameFile For Input As #1
       '(the rtf template name is in the first line)
       Line Input #1, templateName
       While Not EOF(1)
          Line Input #1, fieldName
          With oPopup.Controls.Add
           .Caption = fieldName
           .Parameter = fieldName
           .OnAction = "OnInsertField"
        End With
       Wend
    Close #1
    I would be eternally grateful if you have any ideas.

    Reverend
    Last edited by Reverend; 05-26-2021 at 07:46 AM. Reason: making the code clearer

Tags for this Thread

Posting Permissions

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