I need to create a text file with the name of the active workbook, but with the .txt extension. I use the following code:
Public Sub textfile()
Dim fso As Variant, ts As Variant
Dim tempFileName As String
Set fso = CreateObject("Scripting.FileSystemObject")
tempFileName = ActiveWorkbook.FullName + ".txt"
Debug.Print tempFileName
Set ts = fso.CreateTextFile(tempFileName)
ts.WriteLine "Hello"
ts.Close
End Sub
With local file, it works perfectly. But if the file is on OneDrive, it gives error 52 "bad file name or number". The path to the file is:
xxx-my.sharepoint.com/personal/yyy_xxx_onmicrosoft_com/Documents/test.xlsx.txt
Any ideas on how to solve this?