Hi, I'm trying to add code to a spreadsheet's worksheets for a Worksheet_Change event and am having problems as the users need to have the "Trust access to Visual Basic Project" turned on in Excels options.
The code I'm using is this
Code:
Sub AddSheetCodeNR(SheetName As String)
Dim nwSheet As Worksheet
Dim UFvbc As VBComponent
Dim name As String
Dim Code As String
Dim rngCell As Range
Dim intLoop As Integer
Dim count As Integer
Set nwSheet = ThisWorkbook.Sheets(SheetName)
DoEvents
On Error Resume Next
Set UFvbc = ActiveWorkbook.VBProject.VBComponents(nwSheet.CodeName)
For Each rngCell In Range("rngSheetChangeModule")
count = UFvbc.CodeModule.CountOfLines + 1
Code = rngCell.Value
UFvbc.CodeModule.InsertLines count, Code
Next rngCell
End Sub
and the code within the named range "rngSheetChangeModule" is
Code:
'Module Created To show when Manual Cells on Manual Sheets were updated last.
'Created By Rowan Ramsay SLF475
'Last Edited on 17/06/08
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strComment As String
'Do nothing if more than one cell is changed or content deleted
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
'Check if its in the Column R if not then Exit Sub
If Not Intersect(Target, Range("A:Q")) Is Nothing Then Exit Sub
If Not Intersect(Target, Range("S:IV")) Is Nothing Then Exit Sub
'Otherwise update the cell in column F of this row
If Left(Target.Value, 10) = "Updated By" Then Exit Sub
Target.Offset(0, 1).ClearComments ' Clear any comments
Target.Offset(0, 1).AddComment "Updated By " & Environ("User") & " : " & Now() ' add new comments with staff ID added from fUserID (Function)
Target.Offset(0, 1).Value = Now() ' Add the date time stamp now to the cell
Target.Offset(0, 1).Interior.ColorIndex = 37 ' colour it for VBA
End Sub
Can anyone show me a way to do this withough needing the "Trust access to Visual Basic Project" turned on??
For information I'm using Excel 2003.
Thasnks in advance..... :)
Rowin_Aboat