Can't enter break mode at this time

G

Guest

I am creating a text box in excel using the following code:

ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=3.75, Top:=722.25, Width:=222, Height:= _
87.75).Select

Question 1:
Stepping through the code gives the "Can't enter break mode at this time"
error. I would ignore it, but I need to step through the code to find out
what is causing my other errors.

Question 2: In the above code, it places the text box in the location I
tell it. (Left=, Top=....) This is referenced from cell A1. Is there a way
for the text box to be placed in a specific cell? (Or be referenced from a
cell other than A1.).

Thanks in advance.
 
D

Dave Peterson

#1. I set a break point before the offending line and after the offending line
and run (F5) that offending line without stepping through it.

#2. I like to use a variable that represents the object. Then I can use that
variable to do other things, too.

Option Explicit
Sub testme()

Dim myRng As Range
Dim OLEObj As OLEObject

Set myRng = ActiveSheet.Range("b9")

With myRng
Set OLEObj = .Parent.OLEObjects.Add(ClassType:="Forms.TextBox.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, _
Top:=.Top, _
Width:=.Width, _
Height:=.Height)

OLEObj.Name = "TextBoxIn_" & .Address(0, 0)
End With

End Sub
 
G

Guest

Thanks Dave. I haven't tried it yet since it won't open up the page I need
(See above new post) but I will try it as soon as I can.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top