+ Reply to Thread
Results 1 to 4 of 4

.xls to .txt output

Hybrid View

  1. #1
    Registered User
    Join Date
    12-23-2016
    Location
    Munich, Germany
    MS-Off Ver
    2010
    Posts
    6

    .xls to .txt output

    I don't know code but am hoping someone out there can help me. I have an Excel file with 4 worksheets. On one of These worksheets I have a setout list (a list with 6x columns for: Nr, Description, BA, Los, X-Coord, Y-Coord).
    I would like to be able to Highlight/select a range from this table, e.g. A10:F50, press a button, and have this data displayed in a .txt-file for me which I can then save to a Folder of my liking. Ideally the column headings (from cells A3:F3) are also pasted into the txt-file above the output text.

    Doesn't seem like it would be too hard (for a coder).
    Anyone got a spare few minutes to Punch out a code that I can paste into VBA and assign to a button?
    thanks in advance!

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,526

    Re: .xls to .txt output

    I did a simple search and found a couple of good results.

    search for

    excel, select range and save as .txt

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: .xls to .txt output

    Sub Macro1()
        Shell "notepad.exe", vbNormalFocus
        Range("A3:F3").Copy
        SendKeys "^V"
        Application.Wait Now + TimeValue("00:00:01")
        Selection.Copy
        SendKeys "^V"
        Application.CutCopyMode = False
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: .xls to .txt output

    I use variation of below code to write large range to txt file (it's currently using "," as separator for columns, you can adjust as needed).

    Public Sub OutPutSelectionToNotePad()
    Dim strPath As String: strPath = "C:\Temp\TempFile.txt" 'Temp file
    Dim intFF As Integer: intFF = FreeFile()
    Dim rString As String: rString = ""
    Dim intShow As Variant
    Dim i As Long, j As Long
    
    Open strPath For Output As #intFF
    myArray = Selection.Value
    
    For i = 1 To UBound(myArray, 1)
        For j = 1 To UBound(myArray, 2)
            rString = rString & IIf(Len(rString) > 0, "," & myArray(i, j), myArray(i, j)) ' change separator as needed
        Next j
        Print #intFF, rString & vbCrLf
        rString = ""
    Next i
    
    Close #intFF
    intShow = Shell("Notepad.exe " & strPath, vbNormalFocus)
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Compare values and output cell titles, able to output multiple results
    By TMG2016 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-07-2016, 11:42 AM
  2. [SOLVED] Array to embed formula and if number of output is met output Blank
    By ywang in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-29-2015, 02:34 AM
  3. [SOLVED] Cell reference, output dates to numeric. Should output as text
    By lifeseeker1019 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-02-2015, 05:51 PM
  4. [SOLVED] Comparing two cells for similarities and output a third cell (if C1 = B1, then output A1)
    By PERFECT777 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-26-2013, 12:37 AM
  5. [SOLVED] Paste variable output (SQL Output) into a single cell.
    By fblaze in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2013, 06:24 AM
  6. Looping through columns to copy output into other sheet, and saving output
    By eludlow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-08-2009, 06:27 AM
  7. Importing several Output sheets into one consolidated Output Sheet
    By Ugh_Der in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2009, 08:58 AM

Tags for this Thread

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