+ Reply to Thread
Results 1 to 12 of 12

VB Code to copy and paste from all text file and paste into single file

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to copy and paste from all text file and paste into single file

    Hello:

    I have number (15) of .txt file in C:\Temp\SourceTxt folder
    I have attached 3 such txt files as samples. (All file names will start will 1,2,3...until 15)
    I need a VB Code to copy the contents of each file and past in text file call AllData.txt in C:\Temp\DestTxt folder.
    I have manually created AllData.txt and attached.

    Please let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: VB Code to copy and paste from all text file and paste into single file

    See attached workbook. There is a button programmed to read all txt files and write all data to Alldatatxt.txt file
    Here is the macro:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by p24leclerc; 04-27-2015 at 07:16 PM.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hi p24:

    Seems to work for me great.
    I will try more and if any problem, I will let you know.
    Thanks a lot.
    Riz

  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hi P24:

    Seems to be some problem.
    Let me check and will let you know.
    Please watch this thread for my finding.
    THanks

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hi P24:

    Please try the following 3 files with your code and check the destination file.
    Not all characters are copied, it misses the last digit I think.
    Let me know your finding.
    Thanks a lot
    Riz
    Attached Files Attached Files

  6. #6
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: VB Code to copy and paste from all text file and paste into single file

    try this macro:
    Please Login or Register  to view this content.
    During my testing of this macro, I tried to remove the quotes characters with a formula and I forgot to remove it.
    Sorry for the inconvenience.

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hello p24:

    Works as expected except please refer to attached competed Destination file.
    As you can see there is blank lines which i need to get rid of.
    Please help modify the code accordingly.

    Let me know if you have any questions.
    Thanks.
    Riz
    Attached Files Attached Files

  8. #8
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: VB Code to copy and paste from all text file and paste into single file

    Try this macro:
    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hi p24:

    Seems to work great.
    Will do more testing and let you know if any issues.
    However, i appreciate all the help you have provided.
    Thanks
    Riz

  10. #10
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hi p24:

    I see a small problem.
    I just put 1 file in the source side with 2 lines of data.
    The above code will copy the data into 1 line in destination location.
    If source has 2 lines then copy it in 2 lines at destination.
    Please help modify the code accordingly.
    Please let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  11. #11
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: VB Code to copy and paste from all text file and paste into single file

    try this macro. It removes all the "spaces", "Cariage return" and "Line feed" from the end of each file.
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to copy and paste from all text file and paste into single file

    Hi P24:

    Superb, seems to work perfectly.

    Thanks a lot..
    Riz

+ 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 copy used range and paste in the body tag of a html file/text file
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 08:34 PM
  2. [SOLVED] VBA code to open many files, copy text, close file, paste text in second work
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-11-2014, 12:59 PM
  3. Replies: 3
    Last Post: 05-21-2013, 08:22 AM
  4. Replies: 13
    Last Post: 11-29-2012, 08:25 PM
  5. Replies: 1
    Last Post: 10-17-2005, 04:05 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