vba 如何将记事本中的文本复制到excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13373700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to copy the text from notepad to excel
提问by user1198699
I am able to open the notepad through excel but dont know how to copy the text.
我可以通过excel打开记事本,但不知道如何复制文本。
I tried that in google also, but not able to get any relevant good info.
我也在谷歌中尝试过,但无法获得任何相关的好信息。
回答by Freak
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
通过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
回答by user9311794
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