+ Reply to Thread
Results 1 to 13 of 13

Automation Error (?) while running Looped VBA Macro

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Automation Error (?) while running Looped VBA Macro

    Good Morning

    While executing my looped Excel VBA code after around 10 runs of the loop all Excel workbooks that are currently open close without notification. There doesn't seem to be a pattern in this happening though, the number of loops it goes through is not constant and it sometimes shows automation error, and sometimes doesn't.

    Unless it is necessary I'm not going to post the code yet because it is rather large and I can't isolate the problem. If there is a way to isolate the problem that would be great. I also know my code could be a lot cleaner but I am still learning a lot of the simple tricks regarding this.

    Thank you

  2. #2
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Automation Error (?) while running Looped VBA Macro

    What action(s) is your loop performing?

  3. #3
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automation Error (?) while running Looped VBA Macro

    This is the code here:

    Please Login or Register  to view this content.
    It takes a site name from a list and creates a new workbook with data from a single Excel database that relates to that site. Formats the new workbook, saves, and places it in an email if that option is selected.

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

    Re: Automation Error (?) while running Looped VBA Macro

    Can you post the code for the subs that are called with this code?
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automation Error (?) while running Looped VBA Macro

    This is the first Call

    Please Login or Register  to view this content.
    Then this runs

    Please Login or Register  to view this content.
    Then this:

    Please Login or Register  to view this content.
    And finally:
    Please Login or Register  to view this content.

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

    Re: Automation Error (?) while running Looped VBA Macro

    Where does the code error?

  7. #7
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automation Error (?) while running Looped VBA Macro

    Quote Originally Posted by Norie View Post
    Where does the code error?
    That is one of the issues, I have no idea. It starts creating the workbooks without any issues, but once it gets to workbook ~10 it all closes. If you can suggest some way to isolate where the code errors that would be fantastic.

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

    Re: Automation Error (?) while running Looped VBA Macro

    I take it there's no debug option when you get the error?

    You could step through the code using F8.

    Breakpoints (F9) can also be set up to halt the code at certain places.

    You can combine the two.

    For example set up a breakpoint on a line before a section of 'suspicious' code.

    Then run the code to that point as normal and step through the next section of code.

    One place it might be worth looking at is the sub 'Mail_workbook_Outlook' where presumably you are automating Outlook.

  9. #9
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automation Error (?) while running Looped VBA Macro

    Thank you for the quick replies.

    With your tips I've narrowed the crashes down to the MoveInfoFinal sub, but this is where it goes weird. I've placed a breakpoint at the line "Private Sub MoveInfoFinal()" and then hold down F5 to continue when it gets to that block and the whole thing runs fine and doesn't crash for the whole execution. Any idea of what is happening?

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

    Re: Automation Error (?) while running Looped VBA Macro

    Another thing you can do to help find errors is remove code like this.
    Please Login or Register  to view this content.
    I don't know if that will help but perhaps worth a try.

    As for that particular sub, nothing sticks out as a potential problem.

    The code could do with a tidy up, using Activate/Select isn't needed, but I don't know if that would make a difference.

  11. #11
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automation Error (?) while running Looped VBA Macro

    Thank you

    I've tried this as well, still having the issues. Could the speed that the code is running at being the cause?

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

    Re: Automation Error (?) while running Looped VBA Macro

    Have you tried commenting out the call to the sub that you think's causing the problem?

    You could also tidy up the code in that sub.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-28-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automation Error (?) while running Looped VBA Macro

    Thank you Norie, that cleaned code has seemed to fix the problem.

+ 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