2012-11-14 75 views

回答

1

通過VBA 打開記事本文件 「TESTFILE.TXT」,選擇所有的數據,複製並在Excel :)

粘貼,如果你是問有關VBA然後做這樣的

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 
0
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 
+2

你想做什麼?請不要破壞帖子。 –

+0

請查看,https://stackoverflow.com/help/how-to-answer – Daniel

相關問題