VBA to save an excel file as text with custom extension

Hauzz

New Member
Joined
Nov 6, 2018
Messages
6
Likes
0
#1
When you want to save an excel file as tex utf-8 and give it your own extension, use this code and adjust it to your needs.
Code:
Sub SaveFile()
Dim x As Long
Dim sSaveAsFilePath As String, strBouquet As String, Land As Variant
Dim Cel As Range
Dim arrLands() As Variant

On Error GoTo ErrHandler:

Set fso = CreateObject("Scripting.FileSystemObject")

    arrLands = array("Germany", Netherlands""Belgium")

    Items = UBound(arrLands) - LBound(arrLands)
    
    For x = 0 To Items
        If arrLands(x) <> "" Then
        Land = arrLands(x)
        Worksheets(Land).Select
        Set KolomA = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
            For Each Cel In KolomA
                strBouquet = strBouquet & Cel.Value & vbNewLine
            Next
        Filename = "D:\MyFiles\" & Replace("userbouquet." & Land & ".txt", ".txt", ".tv")
        Set out = fso.CreateTextFile(Filename, True, False)
        out.Write strBouquet
        out.Close
        strBouquet = ""
        End If
    Next


    Application.ScreenUpdating = True

    MsgBox "Userbouquet saved."

My_Exit:
Exit Sub

ErrHandler:
MsgBox Err.Description
Resume My_Exit

End Sub
Greets
 
TEST
Top