I've tried all of that. It still opens up in the VB Editor.
The last piece of code that it executes it this:
Sub CreateEventProcedure()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("Sheet88")
Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CreateEventProc("Change", "Worksheet")
LineNum = LineNum + 1
.InsertLines LineNum, "End If "
.InsertLines LineNum, " Range(" & DQUOTE & "ItemDescrip" & DQUOTE & ") = Item"
.InsertLines LineNum, " End If"
.InsertLines LineNum, " Item = rs2!ItemDescr"
.InsertLines LineNum, " If Not rs2.EOF Then"
.InsertLines LineNum, " rs2.Open sql2, conn"
.InsertLines LineNum, " Set rs2 = CreateObject(" & DQUOTE & "ADODB.Recordset" & DQUOTE & ")"
.InsertLines LineNum, " sql2 = " & DQUOTE & "SELECT ItemDescr FROM Items WHERE ItemRef = '" & DQUOTE & "& ItemRef & " & DQUOTE & "'"
.InsertLines LineNum, " ItemRef = Range(" & DQUOTE & "ItemReff" & DQUOTE & " ) "
.InsertLines LineNum, "ElseIf Target = Range(" & DQUOTE & "ItemReff" & DQUOTE & ") Then"
.InsertLines LineNum, " Range(" & DQUOTE & "CustomerName" & DQUOTE & ") = CustName"
.InsertLines LineNum, " End If"
.InsertLines LineNum, " CustName = rs!name"
.InsertLines LineNum, " If Not rs.EOF Then"
.InsertLines LineNum, " rs.Open sql, conn"
.InsertLines LineNum, " Set rs = CreateObject(" & DQUOTE & "ADODB.Recordset" & DQUOTE & ")"
.InsertLines LineNum, " sql = " & DQUOTE & "SELECT Name FROM Customers WHERE CustomerRef = '" & DQUOTE & "& CustRef & " & DQUOTE & "'"
.InsertLines LineNum, " CustRef = Range(" & DQUOTE & "CustomerRefStart" & DQUOTE & ")"
.InsertLines LineNum, " If Target = Range(" & DQUOTE & "CustomerRefStart" & DQUOTE & ") Then"
.InsertLines LineNum, " conn.Open"
.InsertLines LineNum, " conn.ConnectionString = ozConnStr"
.InsertLines LineNum, " ozConnStr = " & DQUOTE & "DRIVER={MySQL ODBC 3.51 Driver};SERVER=tst01.habitaz.co.za;UID=oztech;PORT= 3306;DATABASE=oztech_test;USER=oztech;PASSWORD=fYb42248Z9;OPTION=3; & DQUOTE & """
.InsertLines LineNum, " Set conn = CreateObject(" & DQUOTE & "ADODB.Connection" & DQUOTE & ")"
.InsertLines LineNum, " Dim ItemRef As String"
.InsertLines LineNum, " Dim Item As String"
.InsertLines LineNum, " Dim CustRef As String"
.InsertLines LineNum, " Dim CustName As String"
.InsertLines LineNum, " Dim sql2 As String"
.InsertLines LineNum, " Dim sql As String"
.InsertLines LineNum, " Dim ozConnStr As String"
.InsertLines LineNum, " Dim rs2 As Object"
.InsertLines LineNum, " Dim rs As Object"
.InsertLines LineNum, " Dim conn As Object"
End With
End Sub
Could that be the problem?