Friday, August 1, 2014

Export Range to Pipe Delimit Text File

Macro to export range to pipe delimit textfile -


Option Base 1
Option Explicit

Sub export_range_pipe_delimit()
Dim arr As Variant
Dim i As Long, j As Long
Dim line As String
Dim filename As String
Dim rng As Range
Dim fnum


filename = "C:\Users\ashishkoul\Desktop\Pipe Delimit\sample.txt" ' change file_path here
fnum = FreeFile()
Open filename For Output As fnum
Set rng = Range("a1:ah40000") ' Change range here
arr = rng

For j = LBound(arr) To UBound(arr)
    line = ""
    For i = 1 To rng.Columns.Count
        line = line & "|" & arr(j, i)
    Next
   
    Print #fnum, Right(line, Len(line) - 1)
Next

Close #fnum
End Sub

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...