DemonicWitch
New Member
- Joined
- Apr 27, 2023
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hi all,
a friend of mine created a marco that converts the excel entries into a tab delimited .txt file. Unfortunatley since (i guess) an update, it will always save as ANSI, which causes some e.g. kyrillic symbols to be displayed as ? instead of the actual symbols shown in the excel file.
Here is the code:
Could you please point me to where I need to enter the settings and how? I did some research but it seems like the file creation works differently here.
a friend of mine created a marco that converts the excel entries into a tab delimited .txt file. Unfortunatley since (i guess) an update, it will always save as ANSI, which causes some e.g. kyrillic symbols to be displayed as ? instead of the actual symbols shown in the excel file.
Here is the code:
VBA Code:
Private Sub CommandButton1_Click()
Dim letzteZeilenNummer As Long
Dim zeilenNummer As Long
Dim dateiSpeicherOrt As String
Dim materialNummer As String
Dim sprache As String
Dim nummer As String
Dim text As String
Dim textObjekt As String
Dim textID As String
Dim output As String
Dim strformat As String
'Range("A23").Value = ChrW(&HAC1A)
'Ermittlung der letzten belegten Zeile
letzteZeilenNummer = Tabelle1.Cells(Rows.Count, 1).End(xlUp).Row
output = dateiNameOhneEndung(ThisWorkbook.Name)
'Festlegung des Speicherortes und der Dateibenennung
dateiSpeicherOrt = ThisWorkbook.Path & "\" & output & ".txt"
Open dateiSpeicherOrt For Output As #99
For zeilenNummer = 1 To letzteZeilenNummer
'Auslesen der Materialnummer und der Spalten 2 und 3 aus der jeweiligen Zeile
If zeilenNummer > 1 Then
materialNummer = format(Tabelle1.Cells(zeilenNummer, 1).Value, "000000000000000000")
sprache = SpracheZuIndex(Tabelle1.Cells(zeilenNummer, 2).Value)
nummer = "1"
text = Tabelle1.Cells(zeilenNummer, 3).Value
textObjekt = "MATERIAL"
textID = "PRUE"
strformat = "*"
Const maximaleZeichenAnzahl As Integer = 134
Dim benoetigteOutputZeilen As Integer
Dim restZeichenLetzteZeile As Integer
Dim i As Integer
Dim position As Integer
benoetigteOutputZeilen = Len(text) \ maximaleZeichenAnzahl
restZeichenLetzteZeile = Len(text) Mod maximaleZeichenAnzahl
position = 1
'Schleife für die Befüllung von vollen Zeilen mit 134 Zeichen
For i = 1 To benoetigteOutputZeilen
Print #99, textObjekt & vbTab & textID & vbTab & sprache & vbTab & materialNummer & vbTab & i & vbTab & strformat & vbTab & Mid(text, position, maximaleZeichenAnzahl)
'für jeden Schleifendurchlauf Position erhöht und abholung der nächsten 134 Zeichen
position = position + maximaleZeichenAnzahl
Next i
'letzte Zeile mit dem Rest ausgeben
'oder
'die Zeile auszugeben, die kürzer als 134 Zeichen ist
If restZeichenLetzteZeile > 0 Then
Print #99, textObjekt & vbTab & textID & vbTab & sprache & vbTab & materialNummer & vbTab & i & vbTab & strformat & vbTab & Mid(text, position)
End If
Else
'Übertragung der Überschriften ohne Formatierung
materialNummer = Tabelle1.Cells(zeilenNummer, 1).Value
sprache = Tabelle1.Cells(zeilenNummer, 2).Value
nummer = "No"
text = Tabelle1.Cells(zeilenNummer, 3).Value
textObjekt = "Textobjekt"
textID = "TextID"
strformat = "Format"
Print #99, textObjekt & vbTab & textID & vbTab & sprache & vbTab & materialNummer & vbTab & nummer & vbTab & strformat & vbTab & text
End If
Next zeilenNummer
Close #99
End Sub
Private Function dateiNameOhneEndung(dateiNamen As String) As String
dateiNameOhneEndung = Left(dateiNamen, Len(dateiNamen) - 5)
End Function
Private Function SpracheZuIndex(sprache As String) As String
Dim sprachIndex As String
'trim löscht alle Leerzeichen
Select Case Trim(sprache)
Case "Serbian"
sprachIndex = "0"
Case "Chinese"
sprachIndex = "1"
Case "Thai"
sprachIndex = "2"
Case "Korean"
sprachIndex = "3"
Case "Romanian"
sprachIndex = "4"
Case "Slovenian"
sprachIndex = "5"
Case "Croatian"
sprachIndex = "6"
Case "Malaysian"
sprachIndex = "7"
Case "Ukrainian"
sprachIndex = "8"
Case "Estonian"
sprachIndex = "9"
Case "Arabic"
sprachIndex = "A"
Case "Hebrew"
sprachIndex = "B"
Case "Czech"
sprachIndex = "C"
Case "German"
sprachIndex = "D"
Case "English"
sprachIndex = "E"
Case "French"
sprachIndex = "F"
Case "Greek"
sprachIndex = "G"
Case "Hungarian"
sprachIndex = "H"
Case "Italian"
sprachIndex = "I"
Case "Japanese"
sprachIndex = "J"
Case "Danish"
sprachIndex = "K"
Case "Polish"
sprachIndex = "L"
Case "Chinese trad."
sprachIndex = "M"
Case "Dutch"
sprachIndex = "N"
Case "Norwegian"
sprachIndex = "O"
Case "Portuguese"
sprachIndex = "P"
Case "Slovakian"
sprachIndex = "Q"
Case "Russian"
sprachIndex = "R"
Case "Spanish"
sprachIndex = "S"
Case "Turkish"
sprachIndex = "T"
Case "Finnish"
sprachIndex = "U"
Case "Swedish"
sprachIndex = "V"
Case "Bulgarian"
sprachIndex = "W"
Case "Lithuanian"
sprachIndex = "X"
Case "Latvian"
sprachIndex = "Y"
Case "Customer reserve"
sprachIndex = "Z"
Case "Afrikaans"
sprachIndex = "a"
Case "Icelandic"
sprachIndex = "b"
Case "Catalan"
sprachIndex = "c"
Case "Serbian (Latin)"
sprachIndex = "d"
Case "Indonesian"
sprachIndex = "i"
Case "Vietnamese"
sprachIndex = "fill in manually"
Case Else
sprachIndex = "unbekannt"
End Select
SpracheZuIndex = sprachIndex
End Function
Could you please point me to where I need to enter the settings and how? I did some research but it seems like the file creation works differently here.