How to copy the text from notepad to excel [closed

2019-09-22 03:15发布

I am able to open the notepad through excel but dont know how to copy the text.

I tried that in google also, but not able to get any relevant good info.

2条回答
一夜七次
2楼-- · 2019-09-22 03:32
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Users\Kalim\Desktop\Zeeshan\zeeshan.txt",1)
Dim strLine
do while not objFileToRead.AtEndOfStream
     strLine = objFileToRead.ReadLine()
     msgbox(strLine)
     Set objExcel = CreateObject("Excel.Application")
     Set objWorkbook = objExcel.Workbooks.open("C:\Users\Kalim\Desktop\Zeeshan\test3.xlsx")
     a=Split(strLine,":")
     b=ubound(a)
     For i=0 to b
      If a(0)="50" Then
        objExcel.Cells(3,4).Value = a(1)
      End If
     Next   
     objWorkbook.Save
     objWorkbook.Close
     msgbox("Execution completed")
loop
objFileToRead.Close
查看更多
beautiful°
3楼-- · 2019-09-22 03:42

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

and if you are asking about vba then do like that

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 
查看更多
登录 后发表回答