ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA - Reading the file name and path from cells (https://www.excelbanter.com/excel-programming/288218-vba-reading-file-name-path-cells.html)

fazl

VBA - Reading the file name and path from cells
 
I want to read different text files by running a macro. The code for a
"test" file is:

Workbooks.OpenText Filename:="c:\data\test.dat", Origin:=720, _
StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1),
Array(2, 1), Array _
(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)),
TrailingMinusNumbers:=True

Now, the path of this file is always "c:\data" , the file name will be
on the cell A1(test) and the file extention is always "dat".

what are the changes in the code?

Many thanks in advance

Fazl


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

VBA - Reading the file name and path from cells
 
Workbooks.OpenText Filename:="c:\data\" & _
Range("A1").Value & _
".dat", Origin:=720, _
StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
Comma:=False, _
Space:=True, Other:=False, FieldInfo:= _
Array(Array(1, 1), Array(2, 1), Array _
(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True

--
Regards,
Tom Ogilvy

"fazl " wrote in message
...
I want to read different text files by running a macro. The code for a
"test" file is:

Workbooks.OpenText Filename:="c:\data\test.dat", Origin:=720, _
StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1),
Array(2, 1), Array _
(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)),
TrailingMinusNumbers:=True

Now, the path of this file is always "c:\data" , the file name will be
on the cell A1(test) and the file extention is always "dat".

what are the changes in the code?

Many thanks in advance

Fazl


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 06:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com