I am getting an error when I try to use a filename as a variable with the workbooks.opentext command. If I hardcode the file path and file name, it will work. The variable is being taken from a table on an xlsx file using the CELLS(1,1) and/or RANGE("A2") commands.
I get the following error--that also includes my FILENAME in the error message:
Runtime Error '1004'
File could not be accessed. try one of the following
- make sure the specified folder exists
- make sure the folder that contains the file is not read-only
- make sure the filename does not contain any of the characters < > ? [ ] :
Sub01.txt or *
- make sure file/path name does not contain more than 128
WHY am I getting this error? How can I pass my filename as a variable into the OpenText command using VBA?
Other code online shows that it should work... Should my fname and fpath variables not be declared as STRING?
Please help! Thanks.
Here is a snipet of my code:
Bookmarks