Hello,
I'm trying to refer to a textfile and set that as an array, but i'm met with an error when trying to refer to ThisWorkbook.Path (Bad file name or number)
And I don't understand how to fix it.
I'm using the same type of argument to open/refer to a Workbook, and this works just fine.
I'm currently synced to a OneDrive, and the location of the script will both be in OneDrive clouds and locally saved - so trimming/setting a constant FileName isnt an option.
The debug.print FileName is as follows:
Currently my only solution is setting a "default" FileName to:
"C:\Users\User\OneDrive - Company\folder1\folder_of_document_running_the_script\folderx\foldery\document.txt"
But i'd like for this to be dynamic.
Any clues / tips? - Am I misunderstanding something fundamentally of this method?
Much appreciated
I'm trying to refer to a textfile and set that as an array, but i'm met with an error when trying to refer to ThisWorkbook.Path (Bad file name or number)
And I don't understand how to fix it.
I'm using the same type of argument to open/refer to a Workbook, and this works just fine.
I'm currently synced to a OneDrive, and the location of the script will both be in OneDrive clouds and locally saved - so trimming/setting a constant FileName isnt an option.
The debug.print FileName is as follows:
VBA Code:
Sub test_array()
Dim fso As Object, MyFile As Object
Dim FileName As String, Arr As Variant
FileName = ThisWorkbook.Path & "\folderx\foldery\document.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile(FileName, 1) 'This line gives the error.
Arr = Split(MyFile.ReadAll, vbNewLine)
Workbooks.Open FileName:=ThisWorkbook.Path & "\folderx\exceldocument.xlsx" 'This line works just fine, and opens the correct document.
Debug.Print FileName
End Sub
Currently my only solution is setting a "default" FileName to:
"C:\Users\User\OneDrive - Company\folder1\folder_of_document_running_the_script\folderx\foldery\document.txt"
But i'd like for this to be dynamic.
Any clues / tips? - Am I misunderstanding something fundamentally of this method?
Much appreciated