PDA

View Full Version : [SOLVED] open notepad, select all, copy, paste in excel



ilyaskazi
05-20-2005, 05:02 AM
open notepad file "MYFILE.txt" through vba, select all data, copy and paste in excel

johnske
05-20-2005, 05:37 AM
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})

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
HTH,
John

Bob Phillips
05-20-2005, 05:46 AM
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

You can dynamically loop through file, you don't need to know the # of lines



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

ilyaskazi
05-26-2005, 11:10 PM
MYFILE contains vbTabs in lines

if vbtabs found in any line, then put next tab data on next column's cell.

ilyaskazi
05-27-2005, 02:49 AM
plz somebuddy help me....

TonyJollans
05-27-2005, 03:39 AM
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

ilyaskazi
05-27-2005, 04:59 AM
EXCELLENT !!!!

and thanX for d same..