+ Reply to Thread
Results 1 to 8 of 8

Macro to save excel sheet to a specified location and in txt format

  1. #1
    Registered User
    Join Date
    08-08-2013
    Location
    Tallinn
    MS-Off Ver
    Excel 2010
    Posts
    4

    Macro to save excel sheet to a specified location and in txt format

    Hello!

    I have struggled with this problem for a while now and I hope this forum can help me.

    I have an excel sheet with data which I want to "export" or "savecopyas" to a specific folder so that the current excel file is not affected. I tried "savecopyas" command (ActiveWorkbook.SaveCopyAs "C:\TEMP\XXXX.XLS"

    ) it saves fine, but the txt file that it saves is not something that is readable for example in notebook.

    What I would like get is that I open an excel file, then hit a shortcut key for a macro and then data in that excel sheet is saved as a txt file (Tab-delimited) to a specific folder with a name that is always the same. Also when it saves then it should automatically re-write the previous file without notice.

    I really hope somebody can answer this question.

    Best wishes

    Urmas

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to save excel sheet to a specified location and in txt format

    Hello and welcome to the forum,

    Maybe try this:

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    08-08-2013
    Location
    Tallinn
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to save excel sheet to a specified location and in txt format

    Thank very much!

    Just one question. Is it possible that when the macro saves the file then it saves it as a copy? At the moment when it saves then the original excel file that I'm working on is changed to txt format as well. When I tried to modify your code by replacing ""SaveAs" to "SaveCopyAs" it gives me error: "Compile error: Named argument not found" .

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to save excel sheet to a specified location and in txt format

    SaveCopyAs will save the copy as the same format as the original (not as text). Did you want to save it both as a an xlsm file and a txt file? I assumed you wanted to discard any changes so that the template would be the same and only the text files would change.

  5. #5
    Registered User
    Join Date
    08-08-2013
    Location
    Tallinn
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to save excel sheet to a specified location and in txt format

    Ok, I did not know that. Basically I have an excel file that I open and do not want to save. I would like to save the txt file that is generated from the excel data. The current problem is that when I use the macro that you wrote, the txt file is saved correctly, but the excel takes this saved file as template right away. When I used SaveCopyAs command, then it did not touch the original excel fail anyhow.

    This is just a minor problem and I can work with the macro you gave. Thank you very much for that!

    Urmas
    Last edited by urmas97; 08-09-2013 at 11:30 AM. Reason: spelling

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to save excel sheet to a specified location and in txt format

    Here is an updated version. What it does is creates a new copy of the workbook using the saveas function >> opens the newly created workbook (thereby making it the activeworkbook) >> saves the newly created workbook as a text file >> Closes the newly created workbook without saving >> deletes the newly created workbook.

    Remember to test on a copy of the original as the 'Kill' function has no undo process (also good to backup your work first).

    Please Login or Register  to view this content.
    abousetta

  7. #7
    Registered User
    Join Date
    08-08-2013
    Location
    Tallinn
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to save excel sheet to a specified location and in txt format

    That is great! Thanks for the effort

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to save excel sheet to a specified location and in txt format

    Glad I could help.

    Good luck.

    abousetta

+ 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 each sheet with existing name and to the location specified
    By vivek_work in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-12-2013, 08:21 AM
  2. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  3. Replies: 0
    Last Post: 03-06-2012, 10:23 AM
  4. macro - Save in .xls format/to specific location/name from entered data/show message
    By mimichan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-18-2012, 10:38 AM
  5. macro to save sheet from workbook. Specified location and filename
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2011, 11:47 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