+ Reply to Thread
Results 1 to 10 of 10

VBA Macro to save tab as .txt file

  1. #1
    Registered User
    Join Date
    12-11-2018
    Location
    Didcot, England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Post VBA Macro to save tab as .txt file

    Hi all

    I am trying to achieve the following:

    I have a macro enabled spreadsheet that contains 3 separate tabs, each of which I want to save as a .txt file
    I want to do this by clicking a single button
    I want the text files to be saved in the same folder as the parent excel file, and be named [EXCEL FILE NAME]_[PRE DEFINED TEXT].txt
    I also want to do this in a way that does not modify the original excel workbook

    I am sure this can be done with a button / macro / VBA, I have scoured internet discussion boards but I simply cannot work out how to do it

    Any help would be greatly appreciated
    Thanks
    Chris

  2. #2
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    re: VBA Macro to save tab as .txt file

    Hi Chris

    Welcome to the Forum

    Should be doable, what are you basing the [PRE DEFINED TEXT] on? A cell reference or something else?

    Is it a straight Text file you want to save to or a delimited one?

  3. #3
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    re: VBA Macro to save tab as .txt file

    Chris,

    simple learning exercise for you: Use the macro recorder to record yourself saving all 3 sheets as a .txt file. Then post the resulting mess of code here and we'll clean it up for you and tell you what we've done to clean it up so you can do the same next time you want some code. Slowly but surely you'll be learning VBA.

  4. #4
    Registered User
    Join Date
    12-11-2018
    Location
    Didcot, England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: VBA Macro to save tab as .txt file

    Hi Paul

    Thanks for reply
    The pre defined text can be set. For example the tabs will be called:
    "opts_list"
    "DQ_Cpd_list_
    "DQ_Batch_file"
    or something like that so I just need to concatenate the original XL file name to this to name the text file, for example
    [ORIGINAL XL FILE NAME]_opts_list.txt
    etc etc

    I have been manually saving as tab delimited files, so I'd probably go for these

    Thanks a lot
    Chris

  5. #5
    Registered User
    Join Date
    12-11-2018
    Location
    Didcot, England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: VBA Macro to save tab as .txt file

    Hi, thanks for reply !

    I tried to do this initially.
    I seem to be having problems in that in saving the file/tab as a txt file

    When I go back to the original XL file (after saving the tabs) the macro appears to not have saved in this sheet

    Thanks
    Chris

  6. #6
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: VBA Macro to save tab as .txt file

    Hey Chris

    So it's based on the sheet name?

    In that case try;

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-11-2018
    Location
    Didcot, England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: VBA Macro to save tab as .txt file

    Hi Paul

    Its appears to toggle through the tabs (so appears to be doing something)
    But when I look in the folder the parent XL sheet is stored in, I see no text files

    Thanks a lot
    Chris

  8. #8
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: VBA Macro to save tab as .txt file

    Weird, "works on my machine"

    Are you trying to run it from a network drive?

  9. #9
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: VBA Macro to save tab as .txt file

    If it is a Network drive, then try this...

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    12-11-2018
    Location
    Didcot, England
    MS-Off Ver
    MS Office 2010
    Posts
    5

    Re: VBA Macro to save tab as .txt file

    That worked, thankyou so much !

    Chris

+ 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. [SOLVED] Macro to save file by employee and save as PDF in path
    By jw01 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-18-2017, 11:39 AM
  2. [SOLVED] Need to loop a macro to save images to file - but save to user defined directory.
    By superfurry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2015, 07:49 AM
  3. Macro to Auto save a backup copy in a seperate location OR save file with a pop up
    By kdsanderson30 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2014, 12:38 PM
  4. Macro needed to open "File Save As" and change save file type
    By blainerhett in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2014, 02:40 PM
  5. how to specify a file save path to a save macro
    By Solidstan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-04-2013, 05:33 PM
  6. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  7. Save as macro that specifies file type, file location and takes file name from three cells
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-13-2013, 10:09 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