Consulting

Results 1 to 5 of 5

Thread: Excel VBA Macro Crashing

  1. #1
    VBAX Regular
    Joined
    Jul 2012
    Posts
    6
    Location

    Excel VBA Macro Crashing

    Hi,

    I'm trying to run an excel macro but at various stages it ends up causing MS Excel to crash.

    The macro essentially opens an Excel file which is a blank cashflow template, saves the excel document as a new file with the name of the organisation in the filename, opens an older version of that particular organisations cashflow file, performs a series of "copy and paste" functions from the old template to the new template, and then saves and closes the template.

    The macro then works it way down a list of organisation names, repeating the above process.

    Sometimes the macro will reach the 5th or 6th organisation before Excel crashes, sometimes it will crash further down the list.

    I've stepped through the macro line-by-line, and successfully completed the macro from start to finish without Excel crashing, but when it just "runs", it crashes.

    Please can somebody help explain why this is happening!?

    Thanks
    Kevin

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    post your code and the line it fails on
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    VBAX Regular
    Joined
    Jul 2012
    Posts
    6
    Location
    Quote Originally Posted by CatDaddy
    post your code and the line it fails on
    That's part of the problem - there is no line where the code fails.

    The macro doesn't bug out, just crashes excel. If you step through the macro line-by-line, through the entire, routine it works and does what it's supposed to. It's only when you run the macro at full speed that it crashes, and it crashes at different points, never the same place.

    My only guess is it is something to do with memory usage, but the macro is only 6kb!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try inserting some debug.print statements in the code to see how far it gets sans stepping.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    So why don't you post the whole code simply here ?
    It has probably to do with referring to workbooks/worksheets.
    If you start the macro manually a certain workbook/worksheet is the active one.
    If you start the macro otherwise another workbook/worksheet may be the active one.

Posting Permissions

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