M
matthewgdodds
Thanks to the contributions of this forum I have been able to create a
function which inserts into the CodeModule behind Sheet2 Selection
Change code (as below).
The problem I have is that when the function is called VBE is fired up
and displays the CodeModule it's just written into.
How can I avoid this?
Matthew
Function insertSelectionChange(wkbNew As Workbook)
'Dim wkbNew As Workbook
'Set wkbNew = Workbooks.Add
Dim startPoint As Long
With wkbNew.VBProject.VBComponents("sheet2").CodeModule
startPoint = .CreateEventProc("selectionChange", "worksheet") + 1
..InsertLines startPoint, "'Application.ScreenUpdating = true" &
Chr(13) & _
" If selection.Row = 1 Or _" & Chr(13) & _
" selection.Interior.ColorIndex = 3 Or _" & Chr(13) & _
" selection.Areas.Count > 1 Then Exit Sub" & Chr(13) & _
" If CBool(InStr(1, selection.EntireColumn.End(xlUp), ""Type"")) =
True Then" & Chr(13) & _
" If selection.Rows.Count = 1 And selection.Count = 15 Then" &
Chr(13) & _
" If assayFileModule.carryOverQuery2(selection.Rows.Count) =
True Then" & Chr(13) & _
" Call assayFileModule.storeCmpds_sheet(selection)" &
Chr(13) & _
" Else" & Chr(13) & _
" Exit Sub" & Chr(13) & _
" End If" & Chr(13) & _
" ElseIf selection.Rows.Count = 7 And selection.Count = 105 And
CBool(InStr(1, selection.Cells(1).offset(, -2).Value, ""plate"")) =
True Then" & Chr(13) & _
" If assayFileModule.carryOverQuery2(selection.Rows.Count) =
True Then" & Chr(13) & _
" Call assayFileModule.storeCmpds_sheet(selection)" &
Chr(13) & _
" Else" & Chr(13) & _
" Exit Sub" & Chr(13) & _
" End If" & Chr(13) & _
" End If" & Chr(13) & _
" End If"
End With
End Function
function which inserts into the CodeModule behind Sheet2 Selection
Change code (as below).
The problem I have is that when the function is called VBE is fired up
and displays the CodeModule it's just written into.
How can I avoid this?
Matthew
Function insertSelectionChange(wkbNew As Workbook)
'Dim wkbNew As Workbook
'Set wkbNew = Workbooks.Add
Dim startPoint As Long
With wkbNew.VBProject.VBComponents("sheet2").CodeModule
startPoint = .CreateEventProc("selectionChange", "worksheet") + 1
..InsertLines startPoint, "'Application.ScreenUpdating = true" &
Chr(13) & _
" If selection.Row = 1 Or _" & Chr(13) & _
" selection.Interior.ColorIndex = 3 Or _" & Chr(13) & _
" selection.Areas.Count > 1 Then Exit Sub" & Chr(13) & _
" If CBool(InStr(1, selection.EntireColumn.End(xlUp), ""Type"")) =
True Then" & Chr(13) & _
" If selection.Rows.Count = 1 And selection.Count = 15 Then" &
Chr(13) & _
" If assayFileModule.carryOverQuery2(selection.Rows.Count) =
True Then" & Chr(13) & _
" Call assayFileModule.storeCmpds_sheet(selection)" &
Chr(13) & _
" Else" & Chr(13) & _
" Exit Sub" & Chr(13) & _
" End If" & Chr(13) & _
" ElseIf selection.Rows.Count = 7 And selection.Count = 105 And
CBool(InStr(1, selection.Cells(1).offset(, -2).Value, ""plate"")) =
True Then" & Chr(13) & _
" If assayFileModule.carryOverQuery2(selection.Rows.Count) =
True Then" & Chr(13) & _
" Call assayFileModule.storeCmpds_sheet(selection)" &
Chr(13) & _
" Else" & Chr(13) & _
" Exit Sub" & Chr(13) & _
" End If" & Chr(13) & _
" End If" & Chr(13) & _
" End If"
End With
End Function