View Single Post
 
Old 02-12-2013, 07:29 AM
Geza59 Geza59 is offline Windows XP Office 2003
Novice
 
Join Date: May 2012
Location: Budapest, Hungary
Posts: 20
Geza59 is on a distinguished road
Question How to add a blank line within an exporting sub?

Hi!

Could someone show me how to modify an existing macro that exports some stuff to a text file, so that it will also add a blank line at the end?

Here is the sub macro that I want to modify:
Code:
Sub CommandButton4_Click()


' This macro exports the vote results to the log file

    Dim FileName As String  ' the file to write to
    Dim DataRange As Range  ' the range containing the data to export
    Dim Append As Boolean   ' whether to append or overwrite existing data
    Dim SkipEmptyRows As Boolean ' whether to skip empty rows
    Dim PadRight As Boolean ' whether to pad short fields on the right
    Dim PadChar As String   ' character to use when padding short fields
    Dim FieldSpecs As String ' the columns and number of characters for export
    Dim Result As Long  ' the result of the export procedure.
    
    ' Set up the values to do the export
    ' CHANGE THESE VALUES AS DESIRED
    FileName = "D:\ADATA\~Maci\My Files\~Tarsashaz\Forms\LogFile.txt"
    Set DataRange = Range("D4:Q7")
    Append = True
    SkipEmptyRows = True
    PadRight = True
    PadChar = Space(1)
    FieldSpecs = "D,13|E,6|F,6|G,6|H,6|I,6|J,6|K,6|L,6|M,6|N,6|O,6|P,6|Q,5"
    
    ' Do the actual export
    Result = ExportFixedWidth(FileName, DataRange, Append, _
        SkipEmptyRows, PadRight, PadChar, FieldSpecs)
    ' test the result
    If Result >= 0 Then
        MsgBox Format(Result, "#,##0") & " records exported to file: " & FileName
    Else
        MsgBox "An error occurred exporting the data."
    End If


End Sub
Also, does someone know of a website with code tutorials related to exporting excel data to text file? This is such an interesting and powerful subject.
Reply With Quote