View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Amit Kumar Amit Kumar is offline
external usenet poster
 
Posts: 1
Default Application Crash Whie adding Code lines using VBA

Hi,

Executing the code given below throws an error:
"Microsoft Office Excel has encountered a problem and needs to close. We
are sorry for the inconvenience."

But If I remove first insertLine statement that is ".InsertLines LineNum,
"Private Sub.........." the program is excuting fine.

Please help me on this.

Thanks!!

Sub WriteEventHandler(LabelName As String)
Dim LineNum As Long
Const DQUOTE = """"
Set RenameCodeMod =
ActiveWorkbook.VBProject.VBComponents("Sheet1").Co deModule
With RenameCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, "Private Sub " + LabelName + "_DblClick(ByVal
Cancel As MSForms.ReturnBoolean)"
LineNum = LineNum + 1
.InsertLines LineNum, " CurName = " + Trim(LabelName) + ".Caption"
LineNum = LineNum + 1
.InsertLines LineNum, " newname = InputBox(" + DQUOTE + "Enter
new name for " + DQUOTE + " + CurName, " + DQUOTE + "Rename" + DQUOTE + ",
CurName)"
LineNum = LineNum + 1
.InsertLines LineNum, " If Len(Trim(newname)) 0 Then " +
Trim(LabelName) + ".Caption = Trim(newname)"
LineNum = LineNum + 1
.InsertLines LineNum, "End Sub"
End With
End Sub