+ Reply to Thread
Results 1 to 1 of 1

Macro to export specific columns to txt file from expanding range

Hybrid View

  1. #1
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Macro to export specific columns to txt file from expanding range

    Hi!

    Following macro exports contents of entire worksheet of SheetC to a text file in a specific location. I need help to modify the macro to export data only from Columns I & K.

    Option Explicit
    
    Sub ExportData()
    On Error Resume Next
    Dim wbkExport As Workbook
    Dim shtToExport As Worksheet
        Set shtToExport = ThisWorkbook.Worksheets("SheetC")
        Set wbkExport = Application.Workbooks.Add
        shtToExport.Copy Before:=wbkExport.Worksheets(wbkExport.Worksheets.Count)
        wbkExport.SaveAs Filename:="C:\Data\ExportData.txt", FileFormat:=xlTextMSDOS
        wbkExport.Close SaveChanges:=False
    
    End Sub
    Kindly note the specific properties of the above code:
    1. There are more than one worksheets in the workbook and when the macro is being run, SheetC will not be the active sheet in the foreground, so above macro needs to run in background;
    2. I need to import the data in the .txt file for further processing in another excel file, so using the above specific file format.
    3. The Data text file needs to be replaced automatically without prompts to replace or save or open the resulting file

    Note: Sample File attached

    Thanks
    Attached Files Attached Files
    Last edited by naira; 04-29-2019 at 02:49 AM.

+ 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. Extract specific columns from text file and export to another text file
    By KingTamo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-02-2017, 01:00 AM
  2. Export specific range to txt file
    By Sab_1 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-13-2016, 03:40 PM
  3. VBA macro to export specific range of cells to CSV
    By branys in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-29-2016, 10:58 AM
  4. [SOLVED] Export specific range to text file and import the text file if needed
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2015, 07:38 AM
  5. [SOLVED] I need to export specific columns to a pipe delimiter file instead of entire worksheet.
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2013, 03:50 PM
  6. Macro to export specific range of data to text file for each worksheet
    By sonofamonkey10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2013, 05:43 PM
  7. macro to export a range to a text file?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2006, 09:30 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