EXCEL.exe has created errors and will be closed by Windows.

H

help_wanted

I have a macro that runs from an add-in. In this macro is code t
insertlines in to a Sub Procedure on a different workbook. This is th
code I have so far, but I get the error below when the code reaches th
line:
LineNum = CountOfLines + 1

EXCEL.exe has created errors and will be closed by Windows.

Any help would be greatly appriciated.

Dim cmbBtn As OLEObject
Dim strCmdName As String
Dim ModEvent As CodeModule 'Module to Modified
Dim LineNum As Long 'Line number in module
Dim SubName As String 'Button Code name
Dim strProc As String 'Procedure string
Dim EndS As String 'End sub string
Dim sTab As String 'Tab
Dim LF As String 'Line feed or carriage return

Ap = Chr(34)
sTab = Chr(9)
LF = Chr(13)
EndS = "End Sub"

Set cmbBtn = ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1"
Link:=False, DisplayAsIcon:=False, Left:=395.25, Top:=11.8, Width:=96
Height:=27)

SubName = "Private Sub " & cmbBtn.Name & "_Change()" & LF

strProc = "if" & ActiveSheet.Range("e2").Value = "William Day" & "Then
& ActiveSheet.Range("f2").Value = "DAYWI" & "end if"

Set ModEvent
ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule

With ModEvent
LineNum = CountOfLines + 1
.InsertLines LineNum, SubName & strProc & EndS
End Wit
 
B

Bob Phillips

Not tested it but try

LineNum = .CountOfLines + 1


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
H

help_wanted

Bob...
Thanks for the suggestion and the fast response, but I do still get th
error. Any other suggestions ???

Again thanks for the help
 

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