ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "can't enter break mode" error (https://www.excelbanter.com/excel-programming/416138-cant-enter-break-mode-error.html)

Rocky

"can't enter break mode" error
 
Trying to learn how to use vba to write vba code. Copied this code from
Walkenbach's book to watch how it runs, but when i try to run it, I get the
error message "cant' enter break mode" on
Set NewButton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")

Sub AddSheetAndButton()
Dim NewSheet As Worksheet
Dim Newbutton As OLEObject
Dim Code As String
Dim NextLine As Integer

'Add the sheet
Set NewSheet = Sheets.Add

'Add a CommandButton
Set Newbutton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")
With Newbutton
.Left = 4
.Top = 4
.Width = 100
.Height = 24
.Object.Caption = "Return to Sheet1"
End With

'Add the event handler code
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & " On Error Resume Next" & vbCrLf
Code = Code & " Sheets(""Sheet1"").Activate" & vbCrLf
Code = Code & " If Err <0 Then" & vbCrLf
Code = Code & " MsgBox ""Cannot activete Sheet1.""" & vbCrLf
Code = Code & " End If" & vbCrLf
Code = Code & "End Sub"

With ActiveWorkbook.VBProject.VBComponents(NewSheet.Nam e).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

Have not set any breakpoints in the module.
Any ideas on what could be triggering this?

Tx

JLGWhiz

"can't enter break mode" error
 
The message appears when an Active-X control is added to a worksheet. You
can click continue and the control will be added and the code will continue
to run. It is an anomaly from XL97 era and Microsoft never fixed it and no
longer supports it.
A work around is to use a button from the forms tool bar. In xl 2003 I get
the message when I delete the control.

"Rocky" wrote:

Trying to learn how to use vba to write vba code. Copied this code from
Walkenbach's book to watch how it runs, but when i try to run it, I get the
error message "cant' enter break mode" on
Set NewButton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")

Sub AddSheetAndButton()
Dim NewSheet As Worksheet
Dim Newbutton As OLEObject
Dim Code As String
Dim NextLine As Integer

'Add the sheet
Set NewSheet = Sheets.Add

'Add a CommandButton
Set Newbutton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")
With Newbutton
.Left = 4
.Top = 4
.Width = 100
.Height = 24
.Object.Caption = "Return to Sheet1"
End With

'Add the event handler code
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & " On Error Resume Next" & vbCrLf
Code = Code & " Sheets(""Sheet1"").Activate" & vbCrLf
Code = Code & " If Err <0 Then" & vbCrLf
Code = Code & " MsgBox ""Cannot activete Sheet1.""" & vbCrLf
Code = Code & " End If" & vbCrLf
Code = Code & "End Sub"

With ActiveWorkbook.VBProject.VBComponents(NewSheet.Nam e).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

Have not set any breakpoints in the module.
Any ideas on what could be triggering this?

Tx


JLGWhiz

"can't enter break mode" error
 
This is the syntax I use to add my button and it does not give me the message
when I add it. Only when I delete it manually.

MyDocument.Shapes.AddOLEObject Left:=450, _
Top:=200, Width:=55, Height:=25, ClassType:="Forms.CommandButton.1"

"Rocky" wrote:

Trying to learn how to use vba to write vba code. Copied this code from
Walkenbach's book to watch how it runs, but when i try to run it, I get the
error message "cant' enter break mode" on
Set NewButton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")

Sub AddSheetAndButton()
Dim NewSheet As Worksheet
Dim Newbutton As OLEObject
Dim Code As String
Dim NextLine As Integer

'Add the sheet
Set NewSheet = Sheets.Add

'Add a CommandButton
Set Newbutton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")
With Newbutton
.Left = 4
.Top = 4
.Width = 100
.Height = 24
.Object.Caption = "Return to Sheet1"
End With

'Add the event handler code
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & " On Error Resume Next" & vbCrLf
Code = Code & " Sheets(""Sheet1"").Activate" & vbCrLf
Code = Code & " If Err <0 Then" & vbCrLf
Code = Code & " MsgBox ""Cannot activete Sheet1.""" & vbCrLf
Code = Code & " End If" & vbCrLf
Code = Code & "End Sub"

With ActiveWorkbook.VBProject.VBComponents(NewSheet.Nam e).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

Have not set any breakpoints in the module.
Any ideas on what could be triggering this?

Tx


Rocky

"can't enter break mode" error
 
Thanks for your quick reply, I'll give it a try
Rocky

"JLGWhiz" wrote:

This is the syntax I use to add my button and it does not give me the message
when I add it. Only when I delete it manually.

MyDocument.Shapes.AddOLEObject Left:=450, _
Top:=200, Width:=55, Height:=25, ClassType:="Forms.CommandButton.1"

"Rocky" wrote:

Trying to learn how to use vba to write vba code. Copied this code from
Walkenbach's book to watch how it runs, but when i try to run it, I get the
error message "cant' enter break mode" on
Set NewButton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")

Sub AddSheetAndButton()
Dim NewSheet As Worksheet
Dim Newbutton As OLEObject
Dim Code As String
Dim NextLine As Integer

'Add the sheet
Set NewSheet = Sheets.Add

'Add a CommandButton
Set Newbutton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")
With Newbutton
.Left = 4
.Top = 4
.Width = 100
.Height = 24
.Object.Caption = "Return to Sheet1"
End With

'Add the event handler code
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & " On Error Resume Next" & vbCrLf
Code = Code & " Sheets(""Sheet1"").Activate" & vbCrLf
Code = Code & " If Err <0 Then" & vbCrLf
Code = Code & " MsgBox ""Cannot activete Sheet1.""" & vbCrLf
Code = Code & " End If" & vbCrLf
Code = Code & "End Sub"

With ActiveWorkbook.VBProject.VBComponents(NewSheet.Nam e).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

Have not set any breakpoints in the module.
Any ideas on what could be triggering this?

Tx


Dave Peterson

"can't enter break mode" error
 
Don't step through your code when you're near that line.

Instead put a break point right before that line and put a breakpoint right
after that line.

Then Run (not step) the code.

Rocky wrote:

Trying to learn how to use vba to write vba code. Copied this code from
Walkenbach's book to watch how it runs, but when i try to run it, I get the
error message "cant' enter break mode" on
Set NewButton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")

Sub AddSheetAndButton()
Dim NewSheet As Worksheet
Dim Newbutton As OLEObject
Dim Code As String
Dim NextLine As Integer

'Add the sheet
Set NewSheet = Sheets.Add

'Add a CommandButton
Set Newbutton = NewSheet.OLEObjects.Add("Forms.CommandButton.1")
With Newbutton
.Left = 4
.Top = 4
.Width = 100
.Height = 24
.Object.Caption = "Return to Sheet1"
End With

'Add the event handler code
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & " On Error Resume Next" & vbCrLf
Code = Code & " Sheets(""Sheet1"").Activate" & vbCrLf
Code = Code & " If Err <0 Then" & vbCrLf
Code = Code & " MsgBox ""Cannot activete Sheet1.""" & vbCrLf
Code = Code & " End If" & vbCrLf
Code = Code & "End Sub"

With ActiveWorkbook.VBProject.VBComponents(NewSheet.Nam e).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub

Have not set any breakpoints in the module.
Any ideas on what could be triggering this?

Tx


--

Dave Peterson


All times are GMT +1. The time now is 10:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com