+ Reply to Thread
Results 1 to 5 of 5

Script/macro to save a copy as tab delimited text file and then close original file

  1. #1
    Registered User
    Join Date
    10-02-2015
    Location
    MI
    MS-Off Ver
    2010
    Posts
    3

    Script/macro to save a copy as tab delimited text file and then close original file

    Hello:

    I need a VB Code to save a copy of opened sheet 1 as a tab delimited text file (but not overwrite the original), to a specific path.

    I think this is close, but there are two issues, the resulting text file is basically jibberish and I would like the original Excel sheet to just close after this is ran, not saved.

    Sub SaveExcelToTabDelimitedWithoutQuotes()
    Dim sFilename As String, Path As String
    sFilename = "filename_" & Format(Date, "yyyy-mm-dd") & ".txt"
    Path = "S:\Report_FTP"
    Workbooks.Add
    'Saving the Workbook
    ActiveWorkbook.SaveAs Path & "\" & sFilename

    End Sub


    Please let me know if you have any questions.
    Thanks.
    Last edited by Merlin803; 10-02-2015 at 09:49 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,575

    Re: Script/macro to save a copy as tab delimited text file and then close original file

    Welcome to the Forum! Please paste code between code tags. Click the # icon in a reply toolbar to insert them.

    Use the Sheet's SaveAs method rather than the Workbook's SaveAs. Set the fileformat to xlTextWindows. e.g.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-02-2015
    Location
    MI
    MS-Off Ver
    2010
    Posts
    3

    Re: Script/macro to save a copy as tab delimited text file and then close original file

    Thank you. I gave the following a try but the saved .txt file still contains "jibberish" that is unreadable. On the other hand, if I manually choose to save the sheet as a .txt file, the contents in the saved file are readable.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,575

    Re: Script/macro to save a copy as tab delimited text file and then close original file

    IF you record the macro you will see what you left off.

    , xlTextWindows
    do
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-02-2015
    Location
    MI
    MS-Off Ver
    2010
    Posts
    3

    Re: Script/macro to save a copy as tab delimited text file and then close original file

    Doh! Thanks!!

+ 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. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  2. Replies: 0
    Last Post: 11-24-2012, 02:31 AM
  3. Copy an open file and close the original
    By lancaster in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-01-2009, 10:03 AM
  4. Save CSV file as Pipe delimited text file
    By germantim in forum Excel General
    Replies: 5
    Last Post: 08-11-2009, 12:21 PM
  5. Replies: 1
    Last Post: 05-03-2005, 06:06 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