+ Reply to Thread
Results 1 to 5 of 5

MS Excel VB to export data to text file

  1. #1
    Registered User
    Join Date
    09-15-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    4

    MS Excel VB to export data to text file

    Hi,

    I am new vba and like to know if there is a way using excel macros or VB in Windows to:


    1) create .txt file name using value or content of a cell say A1. It could be alphanumeric.
    2) Then get excel data from range column B, where the rows count varies. Should get only data not empty rows of column B.
    3) Save the text file on desktop, show message of exact location of file saved.
    4) Now as its saved, if macro is run again with same text file name, should replace the previous file if its name is same.
    5) The macro is run from another sheet in same workbook, not from the sheet which contains data. Say Macro is from sheet1 and data is in sheet2, the data contains quotes singe or double and pipe, which should not be affected on export.
    6) And the clipboard should be cleared after export, as in this code.
    We are using office 2010. Pleas suggest simple and easiest way.

    Please suggest.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: MS Excel VB to export data to text file

    1. Fname = Worksheets(1).Range("A1") & ".txt"

    2. Something like this.

    4. The code in the thread will overwrite any file with same name.

    3. You can set the path to the desktop.

    5. Just make sure you FULLY QUALIFY the source worksheet. E.g. Print #1, Worksheets(MySheet").Cells(a, 2)

    6. The clipboard isn't used.
    David
    (*) Reputation points appreciated.

  3. #3
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: MS Excel VB to export data to text file

    Hi..

    Place a CommandButton on Sheet1 with the below code in it.

    Tested by having filename in A1 on Sheet2 and the data on Sheet2 Column B (Row 1 down)..

    Change the Filepath (code in Red) to suit.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-15-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: MS Excel VB to export data to text file

    @apo I later thought of having a folder on desktop of users. So, whatever the users desktop location may be, should create folder and save the text file there. I tried this using ur code.

    Please Login or Register  to view this content.
    Thanks for your code and much appreciate it.

  5. #5
    Registered User
    Join Date
    09-15-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: MS Excel VB to export data to text file

    @apo for some reason this script is failing at .writeline Join(Application.Transpose(myArea), vbCrLf). Runtime error '13' Type mismatch. Any suggestions please

+ 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. Export Excel records to seperate text file & compress it to protecte ZIP file
    By firedragon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2012, 10:47 AM
  2. Code to Export Excel Data to Text File
    By ashkash in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-13-2012, 05:59 AM
  3. Export Excel Form Data to Text File
    By The doomed in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2010, 02:29 PM
  4. Export excel file to semicolon delimited text file
    By capitan in forum Excel General
    Replies: 5
    Last Post: 04-06-2005, 11:07 PM
  5. [SOLVED] How do I import text file, analyze data, export results, open next file
    By Geoffro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2005, 04:06 PM

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