Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1624to1628
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Text von Spalten in .txt File

Text von Spalten in .txt File
21.05.2018 16:28:41
Spalten

Hallo, ich brauche eure Hilfe.
Ich möchte Daten von Spalten einer Exceldatei (siehe Anhang) in einer Textdatei (.txt) speichern. Für jede einzelne Spalte soll eine eigene Zeile in der Textdatei angelegt werden und die Symbole in den Zellen (falls vorhanden) der jeweiligen Spalte in einem bestimmten Format erscheinen. Also die erste Zeile der Textdatei soll wie folgt aussehen:
Name1.Name2("20170228", {"A","AAL","AAP","AAPL"}
Nach Name1.Name2(" soll das Datum, welches sich in der jeweiligen Zeile 3 befindet in doppelten Hochkommata stehen. Die Symbole der Spalte sollen in doppelten Hochkommata + geschweifte Klammern stehen. Siehe Beispielzeile.
Vielen Dank im Voraus.
LG
https://www.herber.de/bbs/user/121723.xlsx

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Text von Spalten in .txt File
21.05.2018 16:34:04
Spalten
Hallo Wolfgang,
Name1.Name2 bleibt immer gleich?
Wie sollen die Dateien heißen?
 ABCDEF
1Gruß Sepp
2
3

Anzeige
AW: Text von Spalten in .txt File
21.05.2018 17:09:58
Spalten
Hallo WQolfgang,
als Dateinamen hab ich mal das Datum herangezogen.
Modul Modul1
Option Explicit 
 
Sub createTXTFiles() 
  Dim lngCol As Long, rng As Range, rngCol As Range 
  Dim strFile As String, strPath As String, strText As String 
  Dim FF As Integer 
 
  strPath = "D:\Forum" 
  If Right(strPath, 1) <> "\" Then strPath = strPath & "\" 
 
  With Sheets("Tabelle1")   'Tabellenname - Anpassen! 
    For lngCol = 1 To .Cells(3, .Columns.Count).End(xlToLeft).Column 
      If .Cells(3, lngCol) <> "" Then 
        On Error Resume Next 
        Set rngCol = .Range(.Cells(4, lngCol), .Cells(.Cells(.Rows.Count, lngCol).End(xlUp).Row, _
          lngCol)).SpecialCells(xlCellTypeConstants) 
        Err.Clear 
        On Error GoTo 0 
        If Not rngCol Is Nothing Then 
          strFile = .Cells(3, lngCol).Text & ".txt" 
          strText = "Name1.Name2(""" & .Cells(3, lngCol).Text & """, {""" 
          For Each rng In rngCol 
            If Len(Trim$(rng)) Then strText = strText & rng.Text & """,""" 
          Next 
          strText = Left(strText, Len(strText) - 2) & "}" 
        End If 
        FF = FreeFile 
        Open strPath & strFile For Output As #FF 
        Print #FF, strText 
        Close #FF 
      End If 
    Next 
  End With 
End Sub 

VBA/HTML-CodeConverter, AddIn für Office 2002-2016 - in VBA geschrieben von Lukas Mosimann. Projektbetreuung:RMH Software & Media

Code erstellt und getestet in Office 16 - mit VBAHTML 12.6.0


 ABCDEF
1Gruß Sepp
2
3

Anzeige
Du wolltest ja nur eine Datei!
21.05.2018 17:26:01
Sepp
Hallo Wolfgang,
Modul Modul1
Option Explicit 
 
Sub createTXTFiles() 
  Dim lngCol As Long, rng As Range, rngCol As Range 
  Dim strFile As String, strPath As String, strText As String 
  Dim FF As Integer 
 
  strPath = "D:\Forum"  'Pfad - Anpassen! 
   
  If Right(strPath, 1) <> "\" Then strPath = strPath & "\" 
   
  strFile = "spalten.txt" 'Dateiname - Anpassen! 
   
  With Sheets("Tabelle1")   'Tabellenname - Anpassen! 
    For lngCol = 1 To .Cells(3, .Columns.Count).End(xlToLeft).Column 
      If .Cells(3, lngCol) <> "" Then 
        On Error Resume Next 
        Set rngCol = .Range(.Cells(4, lngCol), .Cells(.Cells(.Rows.Count, lngCol).End(xlUp).Row, _
          lngCol)).SpecialCells(xlCellTypeConstants) 
        Err.Clear 
        On Error GoTo 0 
        If Not rngCol Is Nothing Then 
          strText = strText & "Name1.Name2(""" & .Cells(3, lngCol).Text & """, {""" 
          For Each rng In rngCol 
            If Len(Trim$(rng)) Then strText = strText & rng.Text & """,""" 
          Next 
          strText = Left(strText, Len(strText) - 2) & "}" & vbCrLf 
        End If 
      End If 
    Next 
  End With 
   
  If Len(strText) Then 
    FF = FreeFile 
    Open strPath & strFile For Output As #FF 
    Print #FF, Left(strText, Len(strText) - 2); 
    Close #FF 
  End If 
End Sub 
 

VBA/HTML-CodeConverter, AddIn für Office 2002-2016 - in VBA geschrieben von Lukas Mosimann. Projektbetreuung:RMH Software & Media

Code erstellt und getestet in Office 16 - mit VBAHTML 12.6.0


 ABCDEF
1Gruß Sepp
2
3

Anzeige
AW: Du wolltest ja nur eine Datei!
21.05.2018 21:50:02
Gig
Hallo Sepp,
Funktioniert prima!
Vielen Dank!
AW: Du wolltest ja nur eine Datei!
21.05.2018 21:52:05
Gig
Vielen Dank Sepp.
Funktioniert prima!!

303 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige