Consulting

Results 1 to 7 of 7

Thread: open notepad, select all, copy, paste in excel

  1. #1

    Arrow open notepad, select all, copy, paste in excel

    open notepad file "MYFILE.txt" through vba, select all data, copy and paste in excel

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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
    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.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by johnske
    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

  4. #4
    MYFILE contains vbTabs in lines

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

  5. #5
    plz somebuddy help me....

  6. #6
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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

  7. #7
    EXCELLENT !!!!

    and thanX for d same..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •