+ Reply to Thread
Results 1 to 5 of 5

Save Worksheet at .txt

  1. #1
    Registered User
    Join Date
    03-14-2006
    Posts
    23

    Save Worksheet at .txt

    Hello. I would like a macro to save a worksheet as a .csv file in a folder on my C drive. The worksheet will vary in size (rows and columns). The sheet must use tabs as a delimiter.

    Thanks for your help!

  2. #2
    Tom Ogilvy
    Guest

    RE: Save Worksheet at .txt

    A CSV file uses commas as delimiters

    Activesheet.copy
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs "C:\Myfolder\Myfile.txt", xlText
    Application.DisplayAlerts = True
    Activeworkbook.Close SaveChanges:=False

    --
    Regards,
    Tom Ogilvy

    "Sandeman" wrote:

    >
    > Hello. I would like a macro to save a worksheet as a .csv file in a
    > folder on my C drive. The worksheet will vary in size (rows and
    > columns). The sheet must use tabs as a delimiter.
    >
    > Thanks for your help!
    >
    >
    > --
    > Sandeman
    > ------------------------------------------------------------------------
    > Sandeman's Profile: http://www.excelforum.com/member.php...o&userid=32440
    > View this thread: http://www.excelforum.com/showthread...hreadid=529220
    >
    >


  3. #3
    Registered User
    Join Date
    03-14-2006
    Posts
    23
    Thanks Tom. Doesn't appear to work though as I get an error stating some of the cells contain more than 255 characters, which stops the macro in its tracks. Is there a workaround or another option?

  4. #4
    Dave Peterson
    Guest

    Re: Save Worksheet at .txt

    Maybe

    Dim wks As Worksheet
    Dim newWks As Worksheet

    Set wks = ActiveSheet
    wks.Copy
    Set newWks = ActiveSheet
    wks.Cells.Copy
    newWks.Range("a1").PasteSpecial Paste:=xlPasteValues

    Application.DisplayAlerts = False
    newWks.Parent.SaveAs "C:\Myfile.txt", xlText
    Application.DisplayAlerts = True
    newWks.Parent.Close SaveChanges:=False



    Sandeman wrote:
    >
    > Thanks Tom. Doesn't appear to work though as I get an error stating
    > some of the cells contain more than 255 characters, which stops the
    > macro in its tracks. Is there a workaround or another option?
    >
    > --
    > Sandeman
    > ------------------------------------------------------------------------
    > Sandeman's Profile: http://www.excelforum.com/member.php...o&userid=32440
    > View this thread: http://www.excelforum.com/showthread...hreadid=529220


    --

    Dave Peterson

  5. #5
    Registered User
    Join Date
    03-14-2006
    Posts
    23
    That's the ticket. Thanks Dave.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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