Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    write to '.txt' file (excel 97+)

    Is it possible to save selected range of cells to a disk file in standard txt format.---- The "long way " is to open a new excel workbook, copy the required cells/range and paste them into sheet 1 of the new workbook and then do a "save as .txt file" --this is long and tedious ----is it possible to write a vba macro which would save me going thru all the above mentioned steps?
    Thanx
    Smbs

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: write to '.txt' file (excel 97+)

    Yes, a VBA macro is possible. A beginning is selecting Tools|Macro|Record New Macro and stepping through all the details you've described. When you've finished, select Tools|Macro|Visual Basic Editor (Alt + F11). Go to the view window in the top left hand corner. In that window, a little way under where the cursor is, there will be a folder called Modules. Open it and double click on the Macro icon inside the folder. You will then see the VBA code for what you've just done.

    Most of the code will be reusable for the next time you want to carry out this exercise. What'll you probably want to keep in particular is the point from where you've selected the Range you want to process up to (round about) where you choose the file name for the text file. By reading the contents of the Module, you should be able work out where that stretch is. Keep the very first and last lines of the Macro and the part which I've just mentioned. Deactivate the rest of the code by "commenting out". (The easiest way to do this is to make sure the Edit Toolbar (in the Visual Basic Editor) is showing - Tools|Options. Select the code you want to deactivate and then click on the 8th icon along from the left hand end.) This will make the text turn green. Once you're certain you won't need this code, then you can delete it. In the meantime, the compiler will ignore it.

    Commenting out can also be achieved item by item by putting a single quotation mark the ' sign in front of each line (or part of a line) of code you wish to deactivate. Removing the ' sign reactivates it.

    Save your macro and then test it on another example by selecting Tools|Macro|Macros (Alt + F8) and choosing Run. If the macro doesn't perform, select Debug from the dialog box. In the Visual Basic Editor, the part of the code causing problems will be highlighted in yellow. This may bring you back with more questions.

    Once you've gone some way to having a working macro, you can search the Lounge on issues relating to certain steps; as well as on ways of making your code run faster.

    Hope this helps
    Gre

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: write to '.txt' file (excel 97+)

    You need to look at <A target="_blank" HREF=http://www.cpearson.com/excel/imptext.htm>Chip Pearson's site.</A>

    I am using this and it works wonderfully.

  4. #4
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: write to '.txt' file (excel 97+)

    Thanx Guys
    JUst what I needed
    Smbs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •