+ Reply to Thread
Results 1 to 15 of 15

Excel crashes when executing CreateEventProc for Worksheet_Change event

  1. #1
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Excel crashes when executing CreateEventProc for Worksheet_Change event

    Hi Everybody ,
    Iam trying to assign a Worksheet_Change event programmatically while creating the sheet during runtime.The sheets will be created at runtime based on a value in array . So am trying to create a event for the sheet through macro.I tried with the following code to create a event .But when executed excel Crashes abruptly.

    In my program the sheet will be created dynamically in the for Loop as below
    For Each Value In Arr '
    Worksheets.Add
    ActiveSheet.Name = Value
    LoadCode (Value)
    Next Value

    Following is the code which I use,
    sheet As String refers to sheetname which comes as parameter from other method
    Please Login or Register  to view this content.
    Please help me resolve this issue.

    Thanks in Advance

  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: Excel crashes when executing CreateEventProc for Worksheet_Change event

    Why not use the workbook level event SheetChange?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    Hi Norie,
    Can you please suggest me in detail for how to use the workbook level event sheet change . As am a newbie to excel macro , i would like to know how to implement.

    Thanks

  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: Excel crashes when executing CreateEventProc for Worksheet_Change event

    What are you doing with you worksheet level code?

  5. #5
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    Worksheet level code is needed because I need to get to all the cell address of the edited cells for a particular editable row . Am using the Worksheet event change so that i can get cell address of the edited cell.

    The problem occurs when execute the line ,

    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,643

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    The code you've posted is for creating an event in the ThisWorkbook module, not a worksheet module.

    If you want to create a worksheet event the code should look like this.
    Please Login or Register  to view this content.
    However I'm suggesting you don't use this code to create events in the new worksheet.

    Instead you can use the SheetChange event in the ThisWorkbook module.

    The SheetChange event is triggered when any sheet in the workbook is changed.

    It takes 2 arguments, Sh which is the sheet the change has occured on and Target which is the range on that sheet that has been changed.

  7. #7
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    Thanks for your suggestion and Will try the same .My doubt is how can it be invoked from module.Do i need to call the Workbook_SheetChange explicitly in my module??

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

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    No, it's triggered whenever a change is made on any worksheet.

    Why not try it with the code I posted in post #2?

  9. #9
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    Hi norie,
    Your suggestion works but the scenario is I have a method in macro which assigns the formula to each cell row by row for the whole sheet wherever applicable.After this formula assignation the user is allowed to edit some of the specific rows(Other rows will be protected ) , So I need to find the specific user edited cell value in a string which will then be posted to DB .Can you suggest how I can change this Workbook_SheetChange that fits this scenario.

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

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    As I said there are 2 arguments passed to the SheetChange event, Sh and Target.

    Sh is the sheet that has been changed.

    Target is the range that has been changed, ie the cell the user has edited.

  11. #11
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    Thank you very much for your quick response , Will try the same

  12. #12
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    I have tried the same ,The SheetChange event is good option . But the problem is the event is getting triggered when the macro is in run state . In my scenario as mentioned above it is getting invoked when assigning the formulas to the Cells, But i need to trigger the event after the macro run. i.e When the macro is not in running mode.
    Is there any way to check the same.

    Infact because of it is getting triggered when macro is run , Am getting Type mismatch error
    below is the code for the Event
    Please Login or Register  to view this content.
    Last edited by 1man; 01-03-2014 at 04:25 AM.

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    You may use:
    Please Login or Register  to view this content.
    to turn off event code while your macro is running, then use:
    Please Login or Register  to view this content.
    to turn back on when your macro has finished changing the sheets.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

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

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    You would have the same problems using Worksheet_Change.

    If you don't want the change event triggered when the macro is run use Izandol's suggestion.

    If you still get the type mismatch try checking what Target is, specifically how many cells it represents.

  15. #15
    Registered User
    Join Date
    10-17-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Excel crashes when executing CreateEventProc for Worksheet_Change event

    I have used Izandol's Suggestion and it works fine..

    Thanks for your help Norie and Izandol..

+ 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. Excel 2007 crashes when executing activeworkbook.close command
    By rpradeepjain in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-10-2010, 07:28 AM
  2. Worksheet_change executing selectively
    By lfrench in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2007, 04:59 PM
  3. Replies: 5
    Last Post: 02-04-2006, 06:15 PM
  4. [SOLVED] Event procedures for controls added with CreateEventProc
    By John Austin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-24-2005, 12:06 PM
  5. [SOLVED] Event procedures for controls added with CreateEventProc
    By John Austin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2005, 06:06 PM

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