Log in

View Full Version : Error 52: bad file name or number with OneDrive for Business



Reverend
05-26-2021, 06:12 AM
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

gmayor
05-26-2021, 08:49 PM
It is clear that your code cannot resolve the address. Where you go from here I suspect depends on your ability to resolve the variable <companyname>. The following might then work

fieldNameFile = Environ("USERPROFILE") & "\OneDrive - " & "<companyname>" & "\Documents\SoftwareCompany\ReportFields.txt"alternatively change the direction of the path separator in your original code, however this may then produce issues relating to password access.

'MsgBox Left(ActiveDocument.path, 8)
If Left(ActiveDocument.path, 8) = "https://" Then
fieldNameFile = ActiveDocument.path + "/ReportFields.txt"
Else
fieldNameFile = ActiveDocument.path + "\ReportFields.txt"
End If

rossrankins1
10-17-2022, 05:16 AM
Eliminate the incorrect path. To locate the network SysData directory, use Windows Explorer. the System, click. Open a CFG file in Wordpad or Notepad. Search for a section with the [SysData] header.

If FRx Report Server is set up and running in your environment:
a. Remove any MoveTo lines that are present under the [SysData] section.
b. Check to see if the QueDirectory line has a legitimate path.
c. Keep the system saved. CFG, then shut it. If FRx Report Server is not operating, remove the entire [SysData] section. This includes any QueDirectory or MoveTo lines as well as the [SysData] header.
d. Keep the system saved. CFG, then shut it. Now, FRx ought to start up successfully.