A new User deserve an answer, let me try.
You can import a txt file into your spreadsheet via Menu /Data /Import external data (*) and we can use this feature to prepare a macro.
So, start recording a macro (Menu /Macro /Record new macro) while you do the following things:
-select all the cells of the current sheet and clear them (assuming that you want start from a blank worksheet...)
-Select A1
-Menu /Data /Import external data (*) /Import data (*); in the Type of text box, select "Text file"; browse your file system and select any txt file to open
-the Import wizard will open; select Delimited, Next; chech Other (*) and input a "tilde" as the delimiting character (to type a tilde, use the sequence Alt-126 using
the numeric pad). With this I assume that your text will never contain a "tilde"; if you cannot be sure of this, then select Fixed lenght (and not Delimited), Next, then remove any separator (a vertical bar) that could have set by default (to remove, doubleclick on them)
-Next, and you'll be at step 3 of 3; I suggest that you format the column as Text (+)
-Finish
-confirm A1 as the destination address, Ok
At this point stop recording the macro (Menu /Macro /Stop recording)
At this point open the vba to edit the macro:
-Menu /Macro /Macro; select the name of your macro (Macro1, maybe) and press Modify (*)
You will read the code of the macro, and the first lines will look like these
Code:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\User1\Documents\TREE_A602.txt", Destination _
:=Range("A1"))
Now, before that lines insert these:
Code:
Reselex:
FullNamex = Application.GetOpenFilename(Filefilter:="Txt Files (*.txt), *.xls,Tutti (*.*),*.*", Title:="Seleziona file")
Mess = ">>Selected " & FullNamex & vbCrLf & ">> Yes to Confirm; NO to Change selection; CANCEL to Exit"
Selex = MsgBox(Prompt:=Mess, Buttons:=vbYesNoCancel)
If Selex = 2 Then GoTo Ext 'Cancel
If Selex = 7 Then GoTo Reselex 'NO = Re-select
SORG = "TEXT; " & FullNamex
And finally modify the original code
1) replace this "TEXT;C:\Documents and Settings\User1\Documents\TREE_A602.txt" (including the "quotation marks") with SORG
So it could look like
Code:
With ActiveSheet.QueryTables.Add(Connection:= _
SORG, Destination _
:=Range("A1"))
[/CODE]
2) add this just before Exit Sub:
Thats all.
The new macro will allow you to select a txt file from the filesystem, clear the worksheet and import this txt.
Notes
(*) all the messages marked (*) could be displayed with different words (my excel is not the english version)
(+) If you wish to import the txt and parse its lines in columns, then modify accordingly the selections on the Import wizard; what I suggested will import each line as a single cell.
When recording the macro, please try doing only what suggested, as any action (ie selecting cells, scrolling down, rigt, left,...) could result in additional, useless code (but not harmful).
If you need further information, just post again.
Bye.