+ Reply to Thread
Results 1 to 43 of 43

Runtime Error 9, open debug and macro completes

  1. #1
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Runtime Error 9, open debug and macro completes

    Hi all

    Got some code which in a nutshell checks workbook name, opens another and sends out some emails.
    Part of the code I'm using gets the 1st workbook name, pastes it into a cell of the 2nd (which has an on change event to call the 2nd macro) which the code uses to set as the workbook:

    Please Login or Register  to view this content.
    Open second workbook
    Please Login or Register  to view this content.
    When the code gets to Workbooks(snm).activate, I get Runtime Error 9 but the code finishes and the emails are sent anyway.

    Does anyone know how I can get around this please?
    Preferably without Application.DisplayAlerts = False or On Error Resume Next

    Thank you
    Last edited by Aaron092; 11-03-2014 at 10:08 AM.

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

    Re: Runtime Error 9, open debug and macro completes

    Which workbook are you trying to activate and how are you trying to activate it?

    Also, where's the code that opens the 2nd workbook?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Hi Norie

    I'm trying to activate the first workbook but the name changes so I can't set it as a definitive name.

    Code to open second workbook:
    Please Login or Register  to view this content.
    This is in Personal.XLSB

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

    Re: Runtime Error 9, open debug and macro completes

    What happens if you use this?
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Didn't do anything. Flashed the screen a few times but no emails were sent.

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

    Re: Runtime Error 9, open debug and macro completes

    Not sure I follow.

    In the original code is this line, which is the one I'm suggesting you replace, meant to trigger something that sends the emails?
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Sorry, no.

    In the Personal XSLB, I have some code which checks the current workbooks name on opening.
    If it's "WSR", then the code will check if another book is open called "GC".
    If the second book, GC, isn't open, a message box pops up asking to run this code.

    The Personal XLSB code gets the WSR books name, for example "WSR29102014" where the number is todays date. That number changes weekly.
    The code then opens the GC book, in Sheet1 Cell K1 puts the WSR name, so K1's vale will be "WSR29102014".

    When K1 changes, there is a macro in the GC workbook to call another macro to send emails based on information in the WSR book.

    This is where I'm getting the issue - where the macro uses K1 cell value to open the workbook.
    Please Login or Register  to view this content.
    It seems to get past this error and complete anyway as it's still sending emails which wouldn't be possible without getting the email addresses from the WSR book.

    Hope that makes sense now

    Thanks

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

    Re: Runtime Error 9, open debug and macro completes

    Why not create a reference to the WSR book and pass that to the sub in the GC workbook that sends the emails?

  9. #9
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    How would I do that, please?

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

    Re: Runtime Error 9, open debug and macro completes

    I'm not 100% sure because I don't know when, or how, you are setting the value of WorkbookName.

  11. #11
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Please Login or Register  to view this content.
    That's the code I'm using to get the filename - can't remember what site I got it from though but it returns just the name of the workbook.
    It's first thing that runs when the user clicks 'OK' to run the code.

    Thanks

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

    Re: Runtime Error 9, open debug and macro completes

    Actually, I should have asked where/when you are opening the workbook that you want to refer to using WorkbookName.

  13. #13
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    The workbook I'm trying to refer to is the one that is opened initially - the WSR workbook.

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

    Re: Runtime Error 9, open debug and macro completes

    So you open the WSR workbook and this calls the code to open the other workbook and send the emails?
    Please Login or Register  to view this content.
    If that's right you should pass the WSR workbook as an argument to OpenGCWB.

    To do that you would change the header of the OpenGCWB to something like this,
    Please Login or Register  to view this content.
    and you would call it like this.
    Please Login or Register  to view this content.
    You would also alter OpenGCWB to refer to wbWSR.

  15. #15
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Thank you, but I put your suggestion in and it kept looping on an attachment in the email and Excel crashed.

    The way it's laid out is:

    1) Open WSR workbook

    2) If name match then call OpenGCWB

    3) OpenGCWB gets the WSR workbook name, opens the GC workbook and pastes the WSR name in K1.

    4) When K1 changes in the GC workbook, it calls another macro within the GC workbook which writes and sends the emails.
    This macro uses the K1 value to activate the WSR workbook to pull information from it

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

    Re: Runtime Error 9, open debug and macro completes

    What I'm really trying to suggest is that instead of using a cell with the workbook name to refer to the workbook you actually pass the workbook.

    How you would do that exactly I'm not sure because I've not seen all the code.

    For example, where's the code for sending the emails.


    PS Why not open the GC workbook, then open the WSR workbook?

  17. #17
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    I've tried opening the GC workbook first, but then I'd have to save the WSR book etc etc. It's easier to have it run when the WSR book opens as it's just sending emails.

    Personal XSLB code
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    This is the full code from the GC workbook
    Please Login or Register  to view this content.
    Thanks

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

    Re: Runtime Error 9, open debug and macro completes

    So how are you opening the WSR workbook?

  19. #19
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Manually.
    At the moment, it's an XLSX file saved to my desktop but normally it's opened straight from an email, no need to save (thus the PersonalXLSB)

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

    Re: Runtime Error 9, open debug and macro completes

    You actually have a reference to the WSR workbook in the code, it's wb that's being passed to app_WorkbookActivate.

    I would pass that reference to the OpenGCWB sub

    Then I would call the WelcomeNEW sub from the OpenGCWB sub and when calling pass the reference to the WSR workbook.

  21. #21
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    OK, I gave that a shot but I think I've gone wrong somewhere as it's not running at all now.
    How would you implement this please?

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

    Re: Runtime Error 9, open debug and macro completes

    Something like this perhaps, which is of course totally untested.

    Code in the Personal.xlsb.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    In the GC workbook.
    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Seems to be working fine up until
    Please Login or Register  to view this content.
    Gives a runtime error of 1004 - 'Cannot run the macro "GC.xslm!WelcomeNEW". ... may be disabled ... '

    Would this be because of the (wbWSR As Workbook) part in the final macro?

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

    Re: Runtime Error 9, open debug and macro completes

    It's probably for some other reason.

    Where in the GC workbook is the sub WelcomeNEW located?

    It should be in a standard module, not a worksheet or workbook module.

  25. #25
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Yep - in a standard module. Module 2.

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

    Re: Runtime Error 9, open debug and macro completes

    The code works for me when I create a mocked up GC workbook with the code in it.

    Does this make any difference?
    Please Login or Register  to view this content.

  27. #27
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Afraid not

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

    Re: Runtime Error 9, open debug and macro completes

    Can you upload the GC workbook, without any sensitive data?

  29. #29
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Should be desesitised enough but still make sense.
    New folder.zip

    I've also included the WSR sheet that triggers the Personal XSLB

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

    Re: Runtime Error 9, open debug and macro completes

    Is the real name of the GC workbook 'Claims Guild.xlsm' and is the sub actually called 'ClaimsWelcomeNEW'?

    If so, have you changed the code to take that into account?

  31. #31
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Yeah I did. Sorry, it's habit for me to shorten or acronym long words.

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

    Re: Runtime Error 9, open debug and macro completes

    Can you post the changed code?
    Last edited by Norie; 10-31-2014 at 09:19 AM.

  33. #33
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Please Login or Register  to view this content.
    Is this what you need?

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

    Re: Runtime Error 9, open debug and macro completes

    It was actually the code to call ClaimsWelcomeNEW I wanted to see.

    Mind you seeing the code for that sub I notice you haven't changed the heading to include the argument wbWSR.

    To include that it would look something like this.
    Please Login or Register  to view this content.

  35. #35
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    I must have taken that out in error when posting it as I've still got it in the Module 2 code. My mistake.

    Please Login or Register  to view this content.
    That is as is from the Personal XLSB

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

    Re: Runtime Error 9, open debug and macro completes

    Try this.
    Please Login or Register  to view this content.

  37. #37
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Still the same 1004 error, can't be found etc

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

    Re: Runtime Error 9, open debug and macro completes

    You did make the change I suggested in post #34?
    Please Login or Register  to view this content.

  39. #39
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    That's in there too

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

    Re: Runtime Error 9, open debug and macro completes

    Can you upload all 3 files?

  41. #41
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    I've included the Personal XLSB code too
    There's only 2 files that are used in the whole process.
    New folder.zip

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

    Re: Runtime Error 9, open debug and macro completes

    Thanks for uploading the files, can't look at them right now but I'll have a proper look later.

  43. #43
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Runtime Error 9, open debug and macro completes

    Hi Norie

    I'm not sure what's happened, but I've gone back to the original code I was using (as I needed to use it) and the error isn't coming up anymore.
    No idea what's different, or what I've done but it seems to be fine.

    Thank you for all your help, it's majorly appreciated

+ 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. Save AS when you open workbook debug error
    By Bpd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2014, 02:47 AM
  2. why is this code returning error AFTER it completes
    By Muzza86 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-24-2014, 09:30 AM
  3. [SOLVED] Runtime error...53; unable to debug
    By vinay.kottur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:34 PM
  4. debug runtime error '424' frm_Stopwatch.Show vbModeless
    By leeroy2612 in forum Excel General
    Replies: 1
    Last Post: 01-21-2012, 05:23 PM
  5. Replies: 1
    Last Post: 08-04-2009, 10:43 PM

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