+ Reply to Thread
Results 1 to 10 of 10

How can I abort a CreateTextFile once started?

  1. #1
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    How can I abort a CreateTextFile once started?

    Greetings! Thanks for looking.

    So I'm writing files based on an excel sheet, so I have this:

    Please Login or Register  to view this content.
    then I "do some stuff", then ultimately
    Please Login or Register  to view this content.
    (I know it should be a.close, but close seems to work fine for some reason).

    The issue is that sometimes the "doing some stuff" between opening file and closing doesn't give any data... in which case I don't want to CLOSE, I want to ABORT/CANCEL that file creation... I haven't found any way to do this, is it possible?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How can I abort a CreateTextFile once started?

    I'm pretty sure this doesn't open a file.
    Please Login or Register  to view this content.
    What exactly is happening after that line?

    Whatever it is perhaps you can stop this ever being executed.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: How can I abort a CreateTextFile once started?

    Thanks Norie, but I have to put
    Please Login or Register  to view this content.
    before I can start writing lines to the file. So more in detail, this is my problem:

    Please Login or Register  to view this content.
    So that way I only write things to the file if my CONDITION is being met. But sometimes, the CONDITION is never met, so I basically have a file with headers and footers, but no data! I would like to be able to add something like this at the end
    Please Login or Register  to view this content.
    you know?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How can I abort a CreateTextFile once started?

    Reorganise the code so that it checks there is something to write before it creates the file.

    If there is something then create the file, write the headers and write the data to the file.

  5. #5
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: How can I abort a CreateTextFile once started?

    uuuuuuuuuuuuuuuuug.......... yeah, I can pre-validate, but then I have to go thru the code twice, once to check, once to write. It solves the problem, but......................

    thanks for checking. I'll leave it open for a bit longer see if anyone knows of a way to Ctrl^C that process... let's see.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How can I abort a CreateTextFile once started?

    You should be able to check if there's data to write without going through the code.

    Where is the data?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How can I abort a CreateTextFile once started?

    Why not just move the ActiveCell test to the top?
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: How can I abort a CreateTextFile once started?

    Yeah, I added a pre-test at the top to see if I should even do the macro or not and that solved my problem, but not my question. Anyway, I guess I'll close it. thanks for the help

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    The answer to the question is no, you can't abort the creation of the file.

    So the solution is to not create it if there's no data.

  10. #10
    Registered User
    Join Date
    08-27-2012
    Location
    Roma, Italia
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: How can I abort a CreateTextFile once started?

    Indeed. Thanks Norie!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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