Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Programmatically Adding Code to a Workbook

I also tried:
Set VBCodeMod = Wb.VBProject.VBComponents("ThisWorkBook").CodeModu le
With VBCodeMod
StartLine = .CountOfLines + 1
.InsertLines StartLine, _
"Private Sub Workbook_Open()" & Chr(13) & _
" ThisWorkbook.Sheets(1).EnableSelection = xlUnlockedCells" &
Chr(13) & _
"End Sub"
End With
And got the same results, code added to workbook, but Excel crashed.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org


"Tom Ogilvy" wrote:

http://www.cpearson.com/excel/vbe.htm

has all the info. Note that the security setting must allow programmatic
access to the VBE.

Tools=Macro=Security then Trusted Publishers tab. checkbox at the bottom
--
Regards,
Tom Ogilvy


"Chaplain Doug" wrote:

Excel 2003. As I create new workbooks, I wish to place the following code
into the workbook:

Private Sub Workbook_Open()
ThisWorkbook.Sheets(1).EnableSelection = xlUnlockedCells
End Sub

How can I do this programmatically?

The reason I need to do this is because as I create the new workbook, I am
copying in a single sheet (Sheets(1)) which is protected and which has only
certin cells unlocked. I only want the user to be able to select the
unlocked cells. Although the EnableSelection=xlUnlockedCells is set in the
original, it does not carry over on the copy. Thus, the need for the
Workbook_Open routine to reset it. Thanks for the help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org

Reply
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
Adding "WorkbookOpen" Code Programmatically [email protected] Excel Programming 1 May 15th 06 08:58 AM
adding code to a workbook programmably Davidg Excel Programming 1 January 10th 06 08:27 AM
How to programmatically access sheets in a workbook by code name Bing Excel Programming 1 December 24th 04 11:44 PM
Adding Code to the This_workbook module of a created workbook RPIJG[_68_] Excel Programming 1 July 9th 04 06:35 PM
Adding Code Module to Workbook Charles Excel Programming 2 January 6th 04 08:43 AM


All times are GMT +1. The time now is 03:13 PM.

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

About Us

"It's about Microsoft Excel"