LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Insert code into worksheets programatically??

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a Button Programatically plus code jlclyde Excel Discussion (Misc queries) 1 December 9th 08 04:29 PM
Delete Code Modules Programatically blatham Excel Discussion (Misc queries) 1 February 3rd 06 05:38 PM
Programatically saving workbook (or worksheet) without the code Hugh Excel Programming 4 October 22nd 04 12:03 AM
Deleting macro code programatically Terry Lowe[_3_] Excel Programming 1 September 1st 04 02:30 AM
Removing VBA Code (programatically) Marnie R Excel Programming 1 February 13th 04 01:02 AM


All times are GMT +1. The time now is 07:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"