Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Anzeige
Inhaltsverzeichnis

Excel als Text speichern

Forumthread: Excel als Text speichern

Excel als Text speichern
28.01.2013 14:37:24
Uwe
Hallo,
in folgendem Makro wird die Mappe als TXT gespeichert, allerdings möchte ich die Abfrage wohin die Datei gespeichert wird umgehen und diese immer auf Laufwerk d:\ abspeichern. Wie müsste das Makro geändert werden?
Danke,
Uwe
Sub Text_File_erstellen()
Dim wks As Worksheet
Dim varFile As Variant
Dim strText As String
Dim Zeile As Long, FF As Integer
varFile = Application.GetSaveAsFilename(InitialFileName:="Text.txt", _
Filefilter:="Textfiles (*.txt), *.txt", _
Title:="Bitte Namen der Textdatei wählen/eingeben")
If varFile = False Then Exit Sub
FF = FreeFile()
Set wks = ActiveSheet
Open varFile For Output As #FF
With wks
For Zeile = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
strText = "[" & .Cells(Zeile, 1).Text & "];[" _
& .Cells(Zeile, 2).Text & "]_[" _
& .Cells(Zeile, 3).Text & "]_[" _
& .Cells(Zeile, 4).Text & "]"
Print #FF, strText
Next Zeile
End With
Close #FF
Set wks = Nothing
End Sub

Anzeige

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

Betreff
Datum
Anwender
Anzeige
AW: Excel als Text speichern
28.01.2013 15:11:45
haw
Hallo Uwe,
so z.B.:
Sub Text_File_erstellen()
Dim wks As Worksheet
Dim varFile As Variant
Dim strText As String
Dim Zeile As Long, FF As Integer
'  varFile = Application.GetSaveAsFilename(InitialFileName:="Text.txt", _
'    Filefilter:="Textfiles (*.txt), *.txt", _
'    Title:="Bitte Namen der Textdatei wählen/eingeben")
varFile = "D:\test.txt"
If varFile = False Then Exit Sub
FF = FreeFile()
Set wks = ActiveSheet
Open varFile For Output As #FF
With wks
For Zeile = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
strText = "[" & .Cells(Zeile, 1).Text & "];[" _
& .Cells(Zeile, 2).Text & "]_[" _
& .Cells(Zeile, 3).Text & "]_[" _
& .Cells(Zeile, 4).Text & "]"
Print #FF, strText
Next Zeile
End With
Close #FF
Set wks = Nothing
End Sub
Gruß
Heinz

Anzeige
AW: Excel als Text speichern
28.01.2013 15:13:08
haw
Hallo Uwe,
so z.B.:
Sub Text_File_erstellen()
Dim wks As Worksheet
Dim varFile As Variant
Dim strText As String
Dim Zeile As Long, FF As Integer
'  varFile = Application.GetSaveAsFilename(InitialFileName:="Text.txt", _
'    Filefilter:="Textfiles (*.txt), *.txt", _
'    Title:="Bitte Namen der Textdatei wählen/eingeben")
varFile = "D:\test.txt"
If varFile = False Then Exit Sub
FF = FreeFile()
Set wks = ActiveSheet
Open varFile For Output As #FF
With wks
For Zeile = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
strText = "[" & .Cells(Zeile, 1).Text & "];[" _
& .Cells(Zeile, 2).Text & "]_[" _
& .Cells(Zeile, 3).Text & "]_[" _
& .Cells(Zeile, 4).Text & "]"
Print #FF, strText
Next Zeile
End With
Close #FF
Set wks = Nothing
End Sub

Gruß
Heinz

Anzeige
AW: Excel als Text speichern
28.01.2013 16:31:51
Uwe
Hallo Heinz,
funktioniert leider nicht. Die Textdatei soll ohne Benutzereingriff automatisch gespeichert werden.
Gruss,
Uwe

AW: Excel als Text speichern
29.01.2013 07:34:38
haw
Hallo Uwe,
ich vermute, du hast die ursprünglichen drei Zeilen nicht auskommentiert.
Dann muss es funktionieren.
Natürlich musst du den Dateinamen (text.txt) an deine Wünsche anpassen.
Gruß
Heinz

Anzeige
AW: Excel als Text speichern
29.01.2013 09:08:45
Uwe
Hallo Heinz,
war wohl ein typisches Montagsproblem, ich habe versehentlich eine Zeile zu viel auskommentiert.
Danke!
Uwe

Forumthreads zu verwandten Themen

Anzeige
Anzeige
Anzeige