+ Reply to Thread
Results 1 to 6 of 6

Macro to import a flat file using 'text to columns'

  1. #1
    Registered User
    Join Date
    08-29-2008
    Location
    England
    Posts
    6

    Macro to import a flat file using 'text to columns'

    Hi there,

    I have a macro which imports a flat file into Excel using the 'text to columns' function. The macro currently works on the basis that the filename is always the same. See text below:

    Please Login or Register  to view this content.
    _ etc etc etc

    My query is that the file I am importing is produced daily and has a date stamp within the name. The file format is always the same but I wondered whether there was code to prompt me to select the file I wish to import, rather than always looking for the same file name?

    Thanks in advance
    Last edited by VBA Noob; 09-03-2008 at 08:46 AM.

  2. #2
    Registered User
    Join Date
    07-18-2008
    Location
    India
    Posts
    68

    Macro to import a flat file using 'text to columns'

    Hi,

    Do you want something like this:

    Please Login or Register  to view this content.
    It will open the open file dialog box to let you select the file to open.

  3. #3
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    how about this:
    Please Login or Register  to view this content.
    There are a lot of arguments I didn't specify that it would be wise to.

    You can also set and unset the defaultfilepath (use XL help) around this - i.e. you might want to store the current defaultfilepath at the beginning of your macro, change it to where you know these csv files are, open the file and reset the defaultfilepath back to where it was when you started.

    HTH

  4. #4
    Registered User
    Join Date
    08-29-2008
    Location
    England
    Posts
    6
    Thanks for the replies.

    Cheeky Charlie does your code work on the basis that this is a csv file that is being imported? The file isn't csv file and so I have this code to import the data in Excel:

    Please Login or Register  to view this content.
    So what I need to do is marry some code to give me a fileopen prompt to select the file I want to import and then tag the above code to it, to import it in the correct alignment.

    Can anybody help??

    Mucho Gracias!
    Last edited by VBA Noob; 09-03-2008 at 01:43 PM.

  5. #5
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Sorry, I didn't check back to your first post carefully enough.

    You got it, and you have everything you need, line 1 of my code uses the getopenfilename command to get the filename. You already have the syntax for how to open it (my bad)

    HTH

  6. #6
    Registered User
    Join Date
    08-29-2008
    Location
    England
    Posts
    6
    Thanks for the reply. I have tried this but I get a "syntax error" message

    Please Login or Register  to view this content.
    Does anybody know what I need to change to get this to work?

    Also, how do I wrap the text of the above code?

    Many thanks

+ 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. Text to Columns
    By cob in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-19-2009, 11:04 AM
  2. Various macro issues linked to DDE
    By JMann in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2008, 08:08 AM
  3. Replies: 1
    Last Post: 08-03-2007, 08:33 AM
  4. Import Data Macro (not-overwriting certain columns)
    By MasterMonk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-19-2007, 11:38 AM
  5. import multiple text file to one excell workbook
    By ggalex in forum Excel General
    Replies: 2
    Last Post: 04-25-2007, 11:29 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