PDA

View Full Version : Solved: Import data from text file



Mandy
07-03-2007, 05:06 AM
hi:hi:
suppose i have two text box.
one for entering the file name
and other to specified a seprator may be (, or ; )

based on this information, i want to write a code behind the command button that can import data from the specified text file into excel .
can any ne help me.

Thanks.

lucas
07-03-2007, 05:58 AM
Hi Mandy,
I'm not sure why you would need those text boxes but...this will show you how to import and decide on a delimiter...don't have time right now to go further into your problem but I'm pretty sure this will get you started...see attached.

Mandy
07-03-2007, 06:13 AM
hello sir
Thanks
This is the excetly same example that i was looking on following web address
http://www.cpearson.com/excel/imptext.htm

can u give me some more time, by explaning the code after the if statement. up end if statement i can understand.
plz if you can give a bit more time that will be really helpful.

Thanks

lucas
07-03-2007, 06:17 AM
This part Mandy?
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep

Mandy
07-03-2007, 06:38 AM
no sir
follwing one


ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1

lucas
07-03-2007, 07:06 AM
ColNdx = SaveColNdx
derived from earlier in the code:
SaveColNdx = ActiveCell.Column

NextPos = InStr(Pos, WholeLine, Sep)
Instr defined as: Returns a Variant (Long) specifying the position of the first occurrence of one string within another
syntax for InStr is: InStr([start, ]string1, string2[, compare])

Mandy
07-03-2007, 07:19 AM
Thanks sir for your time
really thanks:bow:

lucas
07-03-2007, 07:24 AM
Your welcome Mandy. Most of the info is available in the vbe help files. Be sure to mark your thread solved if you got the solution. You can post followup questions after marking it solved.