ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   EXCEL.exe has created errors and will be closed by Windows. (https://www.excelbanter.com/excel-programming/294322-excel-exe-has-created-errors-will-closed-windows.html)

help_wanted[_5_]

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


Bob Phillips[_6_]

EXCEL.exe has created errors and will be closed by Windows.
 
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)

"help_wanted " wrote in message
...
I have a macro that runs from an add-in. In this macro is code to
insertlines in to a Sub Procedure on a different workbook. This is the
code I have so far, but I get the error below when the code reaches the
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 With


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




help_wanted[_6_]

EXCEL.exe has created errors and will be closed by Windows.
 
Bob...
Thanks for the suggestion and the fast response, but I do still get th
error. Any other suggestions ???

Again thanks for the help

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



All times are GMT +1. The time now is 07:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com