+ Reply to Thread
Results 1 to 11 of 11

Text file opening with macro

  1. #1
    Registered User
    Join Date
    12-21-2012
    Location
    Alabama, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Text file opening with macro

    I'm trying to create a macro that will open a text file with the settings I choose. I have a dialog that pops up that allows the user to choose the appropriate file, but it always imports with the default settings, which leaves my data unseperated. Would it be easier to tell it the name of the file based on the date? The text file is always named like this "LaserSch20121221" using todays date. Could I use that to tell it which file to open, and how would I do that? Or would the dialog box be easier, and how would I make sure it imported with those specific settings? I tried this: "
    Please Login or Register  to view this content.
    "
    But that gave me an error. Any help would be greatly appreciated

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Text file opening with macro

    need to see the file for writing the correct code
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    12-21-2012
    Location
    Alabama, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Text file opening with macro

    I can't upload it because it is 991 kb.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Text file opening with macro

    AlexHall,

    Welcome to the forum!
    I just answered a very similar question, see here: http://www.excelforum.com/excel-prog...er-export.html

    [EDIT]:
    Note that in your case, it would be called with "," instead of vbTab because your file is comma delimited:
    Please Login or Register  to view this content.
    Last edited by tigeravatar; 12-21-2012 at 02:53 PM. Reason: Added edit
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    12-21-2012
    Location
    Alabama, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Text file opening with macro

    Please Login or Register  to view this content.
    Where do I put this? I'm probably just overlooking something silly but I can't figure it out.

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Text file opening with macro

    That goes in a standard module. The other code, ImportDelimitedTextFiles, also goes in a standard module. Then just run the tgr macro (you can rename it from tgr to whatever you want)

  7. #7
    Registered User
    Join Date
    12-21-2012
    Location
    Alabama, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Text file opening with macro

    I figured it out. Thank you very much. One more question, how would I get it to skip a column? For instance, column 15 has nothing but "inc" in it and I don't want to import that because for some reason it messes with the calculations excel does throught the rest of my macro

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Text file opening with macro

    Unfortunately there is no way to skip columns via VBA, that has to be done manually
    You could put in the macro to delete that column (if that is a feasible with your current macro/calcs)
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-21-2012
    Location
    Alabama, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Text file opening with macro

    That works beautifully. One more question and I should be done. Is there any way to give it a specific folder to open the text file from? Thank you for all your help

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Text file opening with macro

    Application.FileDialog has a variety of properties that can be manipulated. The one you're looking for is .InitialFileName:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-21-2012
    Location
    Alabama, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Text file opening with macro

    Thank you very much. I'm new to coding this stuff and you've been a great help

+ 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