+ Reply to Thread
Results 1 to 14 of 14

excel vba to insert files in worksheet

  1. #1
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    excel vba to insert files in worksheet

    Hi All,

    Good Day!!

    Since I am new in this forum and this is my first post and I am also new in excel vba field. I am seeking one help which is related to excel vba loop. here is the step which I am looking for.

    1) I have more than 50 different text files with different name in a folder.
    2) I need help to insert the files into worksheets one by one meaning after the first text file's content will be inserted into the first worksheet it will copy the text files content and paste into the summary sheet and the first worksheet will be deleted automatically and again new worksheet will be added and the second text file will be inserted and will copy the text files content in the summary sheet's next row and it will go on as many as text files have into the folder.

    Any help will be appreciable. Thank you.

    Regards,
    Pinaki

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: excel vba to insert files in worksheet

    Can these txt files be opened with excel?

  3. #3
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    Yes these text files will be opened with excel and in the worksheets.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: excel vba to insert files in worksheet

    You can loop through the folder and open each .txt file, copy the contents in the sheet, then close the .txt file

    Edit the folder location in the code.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    Thank you Davesexcel for the code. Here in this code all the text files contents are coming to a singe sheet. It worked properly but can the code be slight change? I mean the first text file will insert in a worksheet and copy the content to the master worksheet then that worksheet will be deleted and again the second text file will be inserted in a worksheet and copy the content to the master worksheet and similarly this will happen with other text files also.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: excel vba to insert files in worksheet

    Why would you do that?

  7. #7
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    Because I have so many .txt files and finally I have to prepare one report in .html format. so in that process as I mentioned above it will be easy to prepare the report and every .txt files are having more or less having same content I mean I have one batch script through which I collect some registry values of almost 100 computers and with those text files I need to prepare report. Thank you.

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: excel vba to insert files in worksheet

    You want to put the sheet in the workbook, then copy the contents of the sheet to a master sheet, then delete the sheet.

    My code just copies the contents of the source sheet to the master sheet, then closes the source workbook..

  9. #9
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    yes correct but I want when the first text file is inserted in the first worksheet it will copy the contents to master sheet and deletes that worksheet and this should happen in similar way with all the text files.

  10. #10
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    For more clarity.. Sheet 1 will be the master sheet, in sheet 2 the first text file will be inserted and the text file contents will be copy in Sheet 1 first row then sheet 2 will be deleted, again sheet 3 will be add and insert the next text file and copy the text files content to Sheet 1 second row and similarly it will go on for other files also.

  11. #11
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: excel vba to insert files in worksheet

    Adding the sheet to the destination workbook is a waste of time.
    Just run the code from the master workbook.

  12. #12
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    Actually that procedure will help me to show in the report row wise and that is the reason I was asking the same. Thank you.

  13. #13
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: excel vba to insert files in worksheet

    I think this should insert all the sheets into the master workbook, then you can do what you want with them after.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-11-2017
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    8

    Re: excel vba to insert files in worksheet

    That's perfect as per expectation. Thank you so much Davesexcel..

+ 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. Insert different hyperlink to the same cell in different excel files
    By nazgool166 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2015, 07:15 AM
  2. Replies: 3
    Last Post: 09-09-2014, 07:13 PM
  3. Replies: 5
    Last Post: 11-19-2013, 04:11 PM
  4. Merging multiple excel files in a folder into one master worksheet in a new worksheet
    By johnny_canuck in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-22-2013, 12:20 PM
  5. [SOLVED] Combine multiple (100+) excel files w/ one worksheet each into one giant worksheet
    By justin11 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-03-2013, 01:05 PM
  6. Replies: 3
    Last Post: 03-12-2006, 06:00 AM
  7. [SOLVED] How to insert pdf files into Excel work book.
    By rowboat in forum Excel General
    Replies: 1
    Last Post: 01-31-2005, 03:06 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