Results 1 to 6 of 6

Trailing Spaces at end of Txt File export

Threaded View

Bill1234 Trailing Spaces at end of Txt... 11-13-2018, 12:51 PM
shg Re: Trailing Spaces at end of... 11-13-2018, 01:33 PM
Bill1234 Re: Trailing Spaces at end of... 11-13-2018, 01:53 PM
shg Re: Trailing Spaces at end of... 11-13-2018, 02:00 PM
Bill1234 Re: Trailing Spaces at end of... 11-13-2018, 02:06 PM
shg Re: Trailing Spaces at end of... 11-13-2018, 02:22 PM
  1. #1
    Registered User
    Join Date
    11-09-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    66

    Trailing Spaces at end of Txt File export

    I am almost finished with a macro to export data from excel to a .txt file. However, when I run the macro, the resulting file has trailing spaces. (See incorrect .txt file) I can't have this, since, where I am uploading will not accept the data. See correct .txt file for what I need-nothing too crazy, just no extra spaces after exported data. Macro is:

    Option Explicit
    
    
    Public Sub ExportToNotepad()
    Dim ws  As Worksheet
    Dim wsData As Variant
    Dim myFileName As String
    Dim FN As Integer
    Dim p As Integer, q As Integer
    Dim path As String
    Dim myString As String
    Dim lastrow As Long, lastcolumn As Long
    Set ws = Worksheets("Sheet1")
    lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
    lastcolumn = ws.Cells(1, Columns.Count).End(xlToLeft).Column
    path = Application.ThisWorkbook.path & "\"
    
    '"C:\Users\wbamford\ShareFile\Shared Folders\NO-Accounting P-Drive\2018"
    
    For p = 1 To lastcolumn
        wsData = ws.Cells(1, p).Value
        If wsData = "" Then Exit Sub
        myFileName = wsData
        myFileName = myFileName & ".txt"
        myFileName = path & myFileName
        MsgBox myFileName
        For q = 2 To lastrow
            myString = myString & "" & ws.Cells(q, p) & vbCrLf
            FN = FreeFile
            Open myFileName For Output As #FN
            Print #FN, myString
            Close #FN
        Next q
        myString = ""
    Next p
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Remove trailing spaces that aren't trailing spaces
    By kersplash in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-10-2018, 04:18 AM
  2. [SOLVED] VBA to export text file with fixed width/padded spaces
    By hopegriffin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-03-2017, 06:04 PM
  3. Macro delete trailing spaces (1 million line file)
    By Ayadin in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-11-2016, 04:41 AM
  4. [SOLVED] Help for macro to export to text file with certain amount of spaces.
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2013, 12:27 PM
  5. VBA Macro to export cells to text file and add extra spaces
    By kmfdm515 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2013, 03:50 AM
  6. [SOLVED] Remove Trailing Spaces
    By andrewc in forum Excel General
    Replies: 2
    Last Post: 09-18-2013, 12:56 PM
  7. Excel keep trailing spaces for prn
    By DKY in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2011, 03:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1