+ Reply to Thread
Results 1 to 20 of 20

VBA Macro to load .txt data in various spreadsheets at the end of each file (accumulating)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    268

    Re: VBA Macro to load .txt data in various spreadsheets at the end of each file (accumulat

    I got this error while clicking in the macro button:
    Run-time error '1004'

    'File1.txt' could not be found. Check the spelling of the file name, and verify that the file location is correct.

    If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or delete.

    I checked the file name is correct and it is located in the same directory of Main.xlsx. I did exactly what you said.

    Where in the code the file1.txt is being specified? For example if I have another file with another name, how should I add it? Let`s say I have a file named XAD5E.txt

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA Macro to load .txt data in various spreadsheets at the end of each file (accumulat

    Hi trizzo
    I'm attaching your files with the Button and the Code embedded. As previously indicated, all of these files should be located (by themselves) in one Folder. You'll notice that Main is now Mail.xlsm...Main.xlsx is gone. I wrote the code in Main.xlsx then saved it as Main.xlsm. Main.xlsx was then deleted. Play with these files...the code has been tested and does work for me with these files.

    Regarding this
    Where in the code the file1.txt is being specified?
    The code looks at every .xlsx file in the folder. If the found file name is not the file that's running the code (in this case Main but it can be anything), the .xlsx file is opened. So, in our case, it finds File1.xlsx and opens it. The code then looks for a .txt file with the same name as the .xlsx file it just opened (File1.txt).
    sp = Split(MyFile, ".")(0) & ".txt"
    If it doesn't find it you get the error message you received. Error checking can and should be built into the code to pass the File if this situation exists.

    Regarding this
    Let`s say I have a file named XAD5E.txt
    If you ALSO have a file called XAD5E.xlsx the code will find and open XAD5E.xlsx and XAD5E.txt. If you DON'T have a file called XAD5E.xlsx nothing happens.

    Let me know how it goes.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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