LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating An Event Procedure

I experience the same, but this worked: I added a line to your change proc
( me.Protect UserInterfaceOnly:=true, Password:="secret"), otherwise the
change macro errors since the sheet is protected

So you need to break your macro into two pieces.


Sub BBB()
InsertProc
Application.OnTime Now, "BBB_2"
End Sub

Sub BBB_2()
Application.EnableEvents = False
Columns("H:H").Locked = False ' ---This line
ActiveSheet.Protect Password:="secret", Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.EnableEvents = True

End Sub
Sub InsertProc()
Dim sname As String
Dim StartLine As Long
sname = ActiveSheet.CodeName
With ActiveWorkbook.VBProject.VBComponents(sname).CodeM odule
StartLine = .CreateEventProc("Change", "Worksheet") + 1
.InsertLines StartLine, _
"Dim VRange As Range"
.InsertLines StartLine + 1, _
"Set VRange =ActiveSheet.Columns(""H:H"")"
.InsertLines StartLine + 2, _
"Me.Protect UserInterfaceOnly:=True," & _
" Password:=""secret"""
.InsertLines StartLine + 3, _
"Target.Font.ColorIndex = 3"
.InsertLines StartLine + 4, _
"Target.Font.Bold = True"
End With
End Sub

--
Regards,
Tom Ogilvy

"Les Stout" wrote in message
...
Hello Tom, I do not know what i am doing wrong, i put your code in below
and tried it but i get an error message again ? As soon as i get to the
Colummns ("H:H")line.
The message i get is Run-Tim eerror'-2147417848(890010108)'
Automation error The object invoked has disconnected from its clients. ?

Sub Mycode()

' code
Application.EnableEvents = False
' now call insertproc
InsertProc

' more code
Columns("H:H").Locked = False ' ---This line
ActiveSheet.Protect Password:="secret", Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
' save and close the workbook

' turn on events
Application.EnableEvents = True
SaveFileE
End Sub

To continue i need to protect, save and then send in an e-mail. should i
save it, close and then go and fetch it again ?


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***





 
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
Creating an event procedure question bhofsetz[_6_] Excel Programming 2 June 8th 05 07:03 PM
Event Procedure Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:29 PM
Event Procedure again Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:28 PM
Event Procedure Programming Jeff Armstrong Excel Programming 1 July 29th 04 03:54 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 03:34 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"