Hier ist der Code zum Kopieren der Daten aus einer Textdatei und Einfügen in Excel. Ich habe den Text durch vbNewline
geteilt, aber ich muss es auch durch den Raum teilen.Kopieren von Daten aus Textdatei in Excel
Gibt es eine alternative Methode zum Aufteilen der Daten nach Speicherplatz, und wie teilt man die Daten durch vbNewLine
und Speicherplatz?
On Error Resume Next
Dim objFSO, strTextFile, strData, strLine, arrLines
Const ForReading = 1
path = InputBox("Enter the path :","Select Your Path !","Type your path here")
'name of the text file
strTextFile = path
'Create a File System Object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile, ForReading).ReadAll
'typesplit=inputbox("Enter the type ","Type to split(VbnewLine (or) <Space>)","vbnewline/space")
'Split the text file into lines
arrLines = Split(strData, vbNewLine)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
k = 0
align = InputBox("Enter the type of alignment...(default/horizontal/vertical)", _
"Press h (or) v (or) d")
If (align = "v") Then
rowlimit = InputBox("Enter the row limit")
For i=1 To 10 Step 1
For j=1 To rowlimit Step 1
objExcel.Cells(j, i).Value = arrLines(k)
k = k+1
Next
Next
End If
If (align = "h") Then
collimit = InputBox("Enter the col limit")
For i=1 To 10 Step 1
For j=1 To collimit Step 1
objExcel.Cells(i, j).Value = arrLines(k)
k = k+1
Next
Next
End If
MsgBox("Conversion Finished !!")
Set objFSO = Nothing
Danke Ansgar Wiechers –
Warum sollte der Benutzer Dinge wie Zeilenlimit und Col Limit eingeben? Konnte es nicht aus den Daten abgeleitet werden? Sie könnten Leerzeichen in der Textdatei durch Kommas ersetzen und sie als CSV-Datei speichern, die Excel zu öffnen weiß (und eine Transponierung für die andere Ausrichtung ausführt). Sehen Sie auch, wie Text-zu-Spalten in Excel funktioniert. –
Sie könnten auch versuchen, die Funktion [Text zu Spalten] (https://msdn.microsoft.com/en-us/library/office/ff193593.aspx) zu automatisieren –