D
Dexter
Hello Everyone,
I am very new to Excel programming, but I have written a few simple macros
before. However, I have never really worked with loading information out of a
file and then saving it back.
I have a series of text files which contain data that I want to import. I ran
the macro recorder to import one file that I wanted where I wanted it, but I am
now trying to automate the process. All the files end in .PRN. I write the
name of the file that I want in the "A" row of an Excel spreadsheet, minus the
".PRN". The files are always on a floppy disk in the "A:\" drive. The macro
recorded came up with this line (followed by a whole bunch of other stuff) which
is (sorry if the line wrapping is funny):
With ActiveSheet.QueryTables.Add(Connection:="TEXT;A:\EB1114.PRN",
Destination:=Range("A10"))
I select the cell which has the name of the file in it and load it into a
string as follows:
FileNameToImport = ActiveCell.Value
The active cell contains a the text EB1114, for example. I can make it look
just like what follows the "Connection:=" command by adding:
FileNameToImport = "TEXT;A:\" & FileNameToImport & ".PRN"
However, cannot figure out how to use a string with the "Connection" command.
Can anyone help me?
Thanks a lot in advance,
Dexter
I am very new to Excel programming, but I have written a few simple macros
before. However, I have never really worked with loading information out of a
file and then saving it back.
I have a series of text files which contain data that I want to import. I ran
the macro recorder to import one file that I wanted where I wanted it, but I am
now trying to automate the process. All the files end in .PRN. I write the
name of the file that I want in the "A" row of an Excel spreadsheet, minus the
".PRN". The files are always on a floppy disk in the "A:\" drive. The macro
recorded came up with this line (followed by a whole bunch of other stuff) which
is (sorry if the line wrapping is funny):
With ActiveSheet.QueryTables.Add(Connection:="TEXT;A:\EB1114.PRN",
Destination:=Range("A10"))
I select the cell which has the name of the file in it and load it into a
string as follows:
FileNameToImport = ActiveCell.Value
The active cell contains a the text EB1114, for example. I can make it look
just like what follows the "Connection:=" command by adding:
FileNameToImport = "TEXT;A:\" & FileNameToImport & ".PRN"
However, cannot figure out how to use a string with the "Connection" command.
Can anyone help me?
Thanks a lot in advance,
Dexter