Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here are three code fragments. The first one works propely, the second two
cause Excel to crash. Can someone tell me what I am doing wrong? Thanks The following code works properly: Dim VBCodeMod As CodeModule Dim LineNum As Long Set VBCodeMod = Workbooks(wb).VBProject.VBComponents("ThisWorkbook ").CodeModule With VBCodeMod LineNum = .CountOfLines + 1 .InsertLines LineNum, _ "Sub Workbook_Open()" & Chr(13) & _ "setLookupList" & Chr(13) & _ "End Sub" End With This code causes excel to crash: Dim VBCodeMod As CodeModule Dim LineNum As Long Set VBCodeMod = Workbooks(wb).VBProject.VBComponents("Sheet1").Cod eModule With VBCodeMod LineNum = .CountOfLines + 1 .InsertLines LineNum, _ "'Private Sub Worksheet_Change(ByVal Target As Range)" & Chr(13) & _ "'doIt Target" & Chr(13) & _ "End Sub" End With Similarly, this code also causes excel to crash: Dim StartLine As Long With Workbooks(wb).VBProject.VBComponents("Sheet1").Cod eModule StartLine = .CreateEventProc("Change", "Worksheet") + 1 .InsertLines StartLine, _ "dotIt Target" End With |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Equation Editor & Excel | Excel Worksheet Functions | |||
VB Editor in Excel | Excel Programming | |||
Picture Editor for Excel | Excel Programming | |||
A few problems Programming to the Visual Basic Editor | Excel Programming | |||
Libraries In Excel VB Editor | Excel Programming |