+ Reply to Thread
Results 1 to 4 of 4

VBA code to insert data from multiple .txt files into one output file template file

  1. #1
    Registered User
    Join Date
    04-21-2015
    Location
    Pinellas, FLorida
    MS-Off Ver
    7
    Posts
    2

    VBA code to insert data from multiple .txt files into one output file template file

    Hello, new at VBA macros and have three .txt files (POLE.txt, CABLES.txt, CONNECTORS.txt) that contain data. I would like to run a macro to pull the data from these files into a specific spot in the prefilled template file (marked by their names) and the output would be called STRUCTURE_OUTPUT.txt.

    Here is how the output file would look before running the macro, it would then pull the data into the appropriate spot.

    STRUCTURE OUTPUT FILE

    UNITS INCHES LBS DEG
    COORDINATES

    <<POLE.txt>>
    <<CABLES.txt>>


    TYPE SPACE FRAME
    MEMBER INCIDENCES


    <<CONNECTORS.txt>>

    Can anyone give me any guidance or help on this would be greatly appreciated.

    Pete

  2. #2
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code to insert data from multiple .txt files into one output file template file

    This could be an extremely simple thing to do if you:

    1) Create text files that include the portions of the test that doesn't change in your sample above. The first text file would have this, including that blank line at the end:
    Please Login or Register  to view this content.
    The second one you would create would have this, including the two blank rows at the top and botton:
    Please Login or Register  to view this content.
    2) Change your filenames to something that puts the files in the correct order when viewed in the folder.

    1Title.txt
    2POLE.txt
    3CABLES.txt
    4Title.txt
    5CONNECTORS.txt


    3) Now this very simply macro which calls Window's own ability to merge text files in a folder:
    Please Login or Register  to view this content.
    You could even create a .BAT file stored in the same folder with just this one line of code, doubleclick the file anytime you want to run it.
    Please Login or Register  to view this content.
    Edit both macros above as needed for your system.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-21-2015
    Location
    Pinellas, FLorida
    MS-Off Ver
    7
    Posts
    2

    Re: VBA code to insert data from multiple .txt files into one output file template file

    Thanks for the quick reply, Jerry. However, I have another preformatted template text file that has text before and around the area where I would like the data to be imported. Can you give me an idea of how to write out the data in that spot?

    DEFINE CABLE NETWORK
    INCLUDE ELEMENTS <<CABLE_NETWORK_ELEM.txt>>
    ATTACH JOINTS <<CABLE_NETWORK_ATTACH.txt>>


    UNITS INCHES KIPS DEG
    <<POLE PROPERTIES FORM.txt>> OR <<STEEL POLE PROPERTIES LOADS.txt>>

  4. #4
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code to insert data from multiple .txt files into one output file template file

    Pretty sure my suggestion in post #2 for splitting that preformatted text file out is the solution.

+ 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] HELP: Copy Data from Multiple CSV files to an output xls file
    By Anatawan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-31-2014, 12:33 AM
  2. Replies: 2
    Last Post: 02-14-2014, 01:39 PM
  3. Replies: 2
    Last Post: 02-08-2014, 04:45 AM
  4. Creating Multiple Output Files from a Master File and updating data between workbooks
    By EXCEL0429 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2013, 11:54 AM
  5. Consolidate Data from Multiple Files (Different File Names) into a Master File
    By dspraveen_23 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-08-2012, 12:59 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