Can someone please tell me why I get a "Can't enter break mode at this time" message when stepping through the following code (using the F8 key) at the 'With NewButton' line?
(This is code from a Walkenbach book, and it runs fine if I don't step through it. I'm using Excel 2007 btw) Thanks!
Sub AddButtonAndCode()
Dim NewSheet As Worksheet
Dim NewButton As OLEObject
Dim Code As String
Dim NextLine As Long
Dim x
' Make sure access to the VBProject is allowed
On Error Resume Next
Set x = ActiveWorkbook.VBProject
If Err <> 0 Then
MsgBox "Your security settings do not allow this macro to run.", vbCritical
On Error GoTo 0
Exit Sub
End If
' 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
Bookmarks