open notepad file "MYFILE.txt" through vba, select all data, copy and paste in excel
open notepad file "MYFILE.txt" through vba, select all data, copy and paste in excel
Hi,
Will this do? (write your own path - the one given here requires the notepad and workbook to be in the same folder {or on desktop})
HTH,Option Explicit Sub ImportText() Dim Text, N& Application.ScreenUpdating = False 'put your own path below Open ActiveWorkbook.Path & "\MYFILE.txt" For Input As #1 On Error Resume Next For N = 1 To 60 '< put num lines to suit Input #1, Text Range("a" & N) = Text Next Close #1 End Sub
John
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
You can dynamically loop through file, you don't need to know the # of linesOriginally Posted by johnske
Sub ImportText() Dim Text Dim i As Long Application.ScreenUpdating = False 'put your own path below Open ActiveWorkbook.Path & "\MYFILE.txt" For Input As #1 i = 1 Do While Not EOF(1) ' Loop until end of file. Input #1, Text Range("a" & i) = Text i = i + 1 Loop Close #1 End Sub
MYFILE contains vbTabs in lines
if vbtabs found in any line, then put next tab data on next column's cell.
plz somebuddy help me....
Why not use Excel's built-in capacity to do this ..
Set myPlace = ActiveCell Workbooks.OpenText _ Filename:=ActiveWorkbook.Path & "\MYFILE.txt", _ DataType:=xlDelimited, Tab:=True ActiveSheet.UsedRange.Copy Destination:=myPlace ActiveWorkbook.Close
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
EXCELLENT !!!!
and thanX for d same..