View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
help_wanted[_5_] help_wanted[_5_] is offline
external usenet poster
 
Posts: 1
Default EXCEL.exe has created errors and will be closed by Windows.

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.Combo Box.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

--
Message posted from http://www.ExcelForum.com