Can't Enter Break Mode at this time

pradee

New Member
Joined
Sep 8, 2018
Messages
18
Hi,
I am trying to add code to the sheet, which is dynamically getting created,
when i a executing the subroutine, am getting the error "Can't Enter Break Mode at this time"
at xLine = .CreateEventProc("Change", "Worksheet")

and folling is my code

Code:
Sub AddSht_AddCode(ByRef wb As Workbook)
    Application.EnableEvents = True
    Dim xPro As VBIDE.VBProject
    Dim xCom As VBIDE.VBComponent
    Dim xMod As VBIDE.CodeModule
    Dim xLine As Long


    'Set wb = Workbooks.Add
    
    With wb
        Set xPro = wb.VBProject
        'Set xCom = xPro.VBComponents(ActiveSheet.CodeName)
        Set xCom = xPro.VBComponents(Sheets("Node Pairing").CodeName)
        Set xMod = xCom.CodeModule


        With xMod
            xLine = .CreateEventProc("Change", "Worksheet")
            xLine = xLine + 1


            .InsertLines xLine, " If SheetPresent(" & """" & "Mac Table" & """" & ") = True  Then"
            xLine = xLine + 1
            .InsertLines xLine, "  call NodeMacChange(Target)"
            xLine = xLine + 1
             .InsertLines xLine, "  End If"
        End With
    End With
    Application.EnableEvents = True


End Sub
Help please
Thanks :)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Are you trying to step through the code? And are you trying to alter the code in the workbook where you are running that code?
 
Upvote 0
@RoryA thanks for Reply, i have written some public sub for adding code to the sheet and am calling that sub from the other sub

am i clear?
 
Upvote 0
Nope. Are you trying to add the code to a sheet in the same workbook that is running the first code?
 
Upvote 0
Yes i am adding the code to the sheet in the same work book,

but the strange thing is it is working fine now , i just changed the function call to the end of the subroutine after all code has been executed,

thanks for replying
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top