View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Simon Murphy[_12_] Simon Murphy[_12_] is offline
external usenet poster
 
Posts: 1
Default InsertLines crashes Excel


Andy
Thanks for the code - that explains things.
There seems to be a prob writing from within a loop.
I suggest you build the string of all routines then write just once
outside a loop.
no idea whats causing the prob
heres some code (seems to work on my pc):


Sub AddCheckBoxes()
' For each cell in the selection, sticks a check box, with a simple
event handler

Dim cel As Range
Dim ctl As OLEObject
Dim strVBA As String

Application.EnableEvents = False

For Each cel In Selection
Set ctl =
ActiveSheet.OLEObjects.Add(Classtype:="Forms.Check Box.1", _
Link:=False, Top:=cel.Top + 2, Left:=cel.Left + 2, Height:=10,
Width:=10)
MsgBox "box in ok?"
DoEvents
strVBA = strVBA & vbCrLf & "Private Sub " & ctl.Name _
& "_Click()" & Chr(13) _
& " MsgBox """ & ctl.Name & """" & Chr(13) _
& "End Sub"
Next cel

With
ActiveWorkbook.VBProject.VBComponents(ActiveSheet. CodeName).CodeModule
InsertLines .CountOfLines + 1, strVBA
End With
MsgBox "code in ok?"
Application.EnableEvents = True

End Sub

cheers
Simon


--
Simon Murphy
------------------------------------------------------------------------
Simon Murphy's Profile: http://www.excelforum.com/member.php...o&userid=26538
View this thread: http://www.excelforum.com/showthread...hreadid=399907