+ Reply to Thread
Results 1 to 4 of 4

VBA to Save CSV as Text

  1. #1
    Registered User
    Join Date
    05-10-2013
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    2

    VBA to Save CSV as Text

    Hi, this is my first post thus I apologize if it is incomplete. Using VBA, I am able to open a CSV file in Notepad yet I am unable to save it as a .txt file. I attempted many other methods (not included here) thus please help. Thanks.

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 02-10-2014 at 05:39 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: VBA to Save CSV as Text

    The reason that your code fails where shown is that VBA is a Microsoft Office environment that doesn't know anything about Notepad. It only knows about Excel, Word, Outlook, PowerPoint, Project, and Visio (and I might be missing one). There is no such thing as "Application.Notepad" built into VBA.

    First, what is your goal? What format do you want the .txt file to be written in? A .csv file is simply a plain text file; the extension tells applications that they can interpret commas as field delimiters. Excel writes a .txt file by using tabs as delimiters, but Notepad does not. If you are in Notepad and write a .csv file as a .txt file, you will get exactly the same thing with a different name.

    If you want a tab delimited file you should open the file in Excel, then save it as .txt, instead of using Notepad.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: VBA to Save CSV as Text

    Or, if you are not interested in changing the delimiter, you could simply invoke the Window's "Rename" command and change the file extension from .csv to .txt. For the record, I don't know how to do this from VBA, but it should work.

    I don't know batch programming either, but this could be something perhaps done in some batch file that would rename *.csv to *.txt or copy *.csv to *.txt or some such command. Again, this would leave the file unchanged (comma is still the delimiter). If you want to convert to a tab delimited file, you will need to use a text editor or excel to replace commas with tabs.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    05-10-2013
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VBA to Save CSV as Text

    Thanks Jeff for adding code tags as well as your explanation. My goal output a customized text file involving pipes(|), etc. from a CSV that I created to feed into a system.

    Thanks to MrShorty, my problem is solved and a solution to the code is:

    Please Login or Register  to view this content.

+ 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. Macro to save text string as an MS-DOS format text document
    By bwink88 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2013, 02:25 PM
  2. Export multiple rows of text to a text file and save with an RDP extension.
    By stephen.wardell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2012, 06:27 AM
  3. Macros To Save Worksheet as New xlsx file & Save Another Worksheet As A Text File
    By KeithT in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-16-2011, 05:13 PM
  4. code to save selected(pre defined)text to text file
    By martindwilson in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-27-2008, 06:51 PM
  5. How to save a value in a text box as a Default for this text box in Excel form?
    By surotkin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2005, 09:36 AM

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