Results 1 to 3 of 3

VBA Code convert data to tab delimited and write data to text file | Not Working

Threaded View

  1. #1
    Registered User
    Join Date
    06-03-2015
    Location
    USA
    MS-Off Ver
    Microsoft Office Professional Plus 2010
    Posts
    12

    VBA Code convert data to tab delimited and write data to text file | Not Working

    I have this VBA code to create a text file, convert my data to tab delimited, and then write the data to the file. This code is added at the end of an 80 line macro that formats the document to be identical to another in formatting to be compared as .txt files through Notepad++.

    Everything is working properly except actually writing the data to the file. I see that the file has been interacted with because of the last saved date and time, but it is not writing any of the data.

         Dim rCell As Range, ws As Worksheet, rRow As Range
         Dim sOutput As String, sFname As String, lFnum As Long
    
           Set ws = ThisWorkbook.Sheets("Sheet1")
        'Open a text file to write
        sFname = "\\SERVER1\Info.txt"
        lFnum = FreeFile
    
        Open sFname For Output As lFnum
        'Loop through the rows
            For Each rRow In ws.UsedRange.Rows
            'Loop through the cells in the rows
                For Each rCell In rRow.Cells
                   If Not IsEmpty(rCell) Then
                     sOutput = sOutput & rCell.Value & vbTab
                   End If
                Next rCell
             'remove the last tab
            If sOutput <> "" Then
                sOutput = Left(sOutput, Len(sOutput) - 1)
            End If
            'write to the file and reinitialize the variables'
            Print #lFnum, sOutput
            sOutput = ""
         Next rRow
        'Close the file
        Close lFnum
    
        MsgBox "Done!"
    Last edited by Leith Ross; 07-06-2015 at 04:42 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA code to convert excel file to tab delimited .txt
    By lbl159 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-01-2015, 03:11 AM
  2. Convert Pipe Delimited Text File into CSV File
    By sachin29feb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2012, 10:47 AM
  3. Macro to convert a mutiple sheet workbook to tab delimited text or fixed width text file
    By chandra 2185 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-05-2012, 10:29 AM
  4. Write Sheet to text file, comma delimited.
    By Screamtruth in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-07-2010, 06:16 AM
  5. [SOLVED] writing data to a tab delimited text file?
    By festdaddy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2005, 05:45 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