Archive of Mr Excel Message Board


Back to Lotus archive index
Back to archive home

Importing into a range from a text file ?

Posted by Mark on March 05, 2001 4:48 AM
I am used to writing in lotus script but need to adapt my worksheet
to suit people with excel. One of the funtions I can't seem to figure out
is how to create a macro that will import all the text from a text file and
place it in a range (starting on a particular cell)

The function in lotus script is written like this...

Sub filepath
Dim filename As String,filepath As String,ext As String
ext=".txt"
filename$=filepath+filename+ext
[a:b2..a:s150].Rangecombinetext filename$

finished:
End Sub

So the main function call of this code is the "Rangecombinetext"

Is there a similar proceedure in excel ? and if so, would I be able to
pop up a file search box so the user can select the file to import ?

Many thanks in advance.

You can email me direct with any responses to mbrady@bigpond.net.au

Mark


Re: Importing into a range from a text file ?

Posted by Dave Hawley on March 05, 2001 5:30 AM


Mark, I have sent a e-mail. I will post it her as well though:

Sub TryThis()

Dim Myfile As String
Myfile = Application.GetSaveAsFilename
If Myfile = "" Then Exit Sub
If Right(Myfile, 3) <> "txt" Then
MsgBox "Sorry, this is not a Text File!", vbCritical
Run "TryThis"
End If
End Sub


OzGrid Business Applications


Re: Importing into a range from a text file ?

Posted by Mark on March 05, 2001 6:09 AM


Thanks Dave..but that sub actually saves a file (as in it saves the workbook) from what I can see.
I actually need to Import the entire contents of a text file into my named range in my workbook.

Mark


Oops, typo try this instead.

Posted by Dave Hawley on March 05, 2001 6:24 AM

Application.GetOpenFilename

Dave
OzGrid Business Applications


Re: Oops, typo try this instead.

Posted by Mark on March 05, 2001 2:33 PM

Thanks Dave, That will open the file as a new sheet.
I still need to figure out how to not open the file but extract the text from it and place them into the range.
I'd like to be able to do this without the need to open a new sheet like I
can in 123. I'll keep hunting. Thanks for your time David.

Marko


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.