C
Caro-Kann Defence
Hi.
I have the following procedure that runs after a bunch of worksheets are
added to a workbook. When the user selects a particular cell on one of the
added worksheets the program evaluates whether a userform should be displayed
to prompt to some information.
The problem I have is that while this procedure runs fine on my machine,
when I distribute this to other users, the code is not added. Is there
something I am missing? As far as I can see, all the references are correct
(though I am not positive on this).
Sub Test
Set dBook = ActiveWorkbook
On Error Resume Next
Application.EnableEvents = False
Application.DisplayAlerts = False
For Each vbc In dBook.VBProject.VBComponents
If Left(vbc.Name, 5) = "Sheet" Then
If vbc.CodeModule.CountOfLines = 0 Then
vbc.CodeModule.InsertLines 1, "Private Sub
Worksheet_SelectionChange(ByVal Target As Range)"
vbc.CodeModule.InsertLines 2, "Dim rng as Range"
vbc.CodeModule.InsertLines 5, " Set rng = Target"
vbc.CodeModule.InsertLines 6, " Call CheckTarget(rng)
"
vbc.CodeModule.InsertLines 10, "End Sub"
End If
End If
Next vbc
Application.EnableEvents = True
Application.DisplayAlerts = True
On Error GoTo 0
End Sub
I have the following procedure that runs after a bunch of worksheets are
added to a workbook. When the user selects a particular cell on one of the
added worksheets the program evaluates whether a userform should be displayed
to prompt to some information.
The problem I have is that while this procedure runs fine on my machine,
when I distribute this to other users, the code is not added. Is there
something I am missing? As far as I can see, all the references are correct
(though I am not positive on this).
Sub Test
Set dBook = ActiveWorkbook
On Error Resume Next
Application.EnableEvents = False
Application.DisplayAlerts = False
For Each vbc In dBook.VBProject.VBComponents
If Left(vbc.Name, 5) = "Sheet" Then
If vbc.CodeModule.CountOfLines = 0 Then
vbc.CodeModule.InsertLines 1, "Private Sub
Worksheet_SelectionChange(ByVal Target As Range)"
vbc.CodeModule.InsertLines 2, "Dim rng as Range"
vbc.CodeModule.InsertLines 5, " Set rng = Target"
vbc.CodeModule.InsertLines 6, " Call CheckTarget(rng)
"
vbc.CodeModule.InsertLines 10, "End Sub"
End If
End If
Next vbc
Application.EnableEvents = True
Application.DisplayAlerts = True
On Error GoTo 0
End Sub