Yes. If you look in VBA help for the Open statement, you see that the filename argument is simply a string expression (any string expression) that evaluates to a valid file name. So you would look up the path for the current workbook (see VBA help for the Path property as it applies to the workbook object). Then use the value or text property to look up the filename in R3C21 (myworksheet.cells(3,21).value where my worksheet is a reference to the desired worksheet). Then use the concatenate operator (&) to piece those two strings together into the final file name.So now the file is written to directory C:\Erwin\Test\Excel\ and than the filename. Is it possible to use the name (test1.txt) from cell R3C21?
Is it possible to save the file in the same folder as the excelfile itself? So if i copy the excel to my other notebook with a different directory it doesn't gives an error?
My file didn't have any quotes in it, so I'm not sure where they are coming from on your end. Try stepping through the code (set a breakpoint at an appropriate spot) and watch what it is doing to see if you can see which statement is adding the quotes.And the textfile is the same as yours. The upcoming problem now is that i don't want the "" signs in the file otherwise the program can't read the textfile.
As written, you will notice the "selectiononly" argument in the "exporttotextfile" procedure. Currently this is set to false, which causes the procedure to write the activesheet. If you select the desired range before running the code and set selectiononly to true, then it will use only that range. If you want to hardcode the range into the procedure, simply set a variable to refer to that range (Set myrange=activesheet.range("F3:F104"))Also the textfile is quite long, I always want to expert cell range R3C6 to R104C6, is this achievable?
Bookmarks