Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Okay, here's what I've found out since yesterday:
Excel crashes when I try to add a click event to run the new macro I imported from another file. This is all being done via VB so what you see is me copying a button, changing the caption, then adding code to the worksheet for the click event associated with the new button: Sub MAJORtoPowerPoint_Button() Windows.Application.Workbooks(2).Activate Sheets("Instructions").Select ActiveSheet.Unprotect "PASSWORD" 'copy an existing button ActiveSheet.Shapes("CommandButton3").Select Selection.Copy 'create the new button ActiveSheet.Paste 'Move it where I want it Selection.ShapeRange.IncrementLeft 175 Selection.ShapeRange.IncrementTop -12 'Change the caption Selection.Object.Caption = "Major to PowerPoint" 'Unprotect the VB Code UnprotectVBProj Pause 3 'insert new click event ActiveWorkbook.VBProject.VBComponents(ActiveWorkbo ok.ActiveSheet.CodeName).CodeModule.AddFromString _ ("Private Sub CommandButton6_Click()" & vbCr & "MAJORtoPowerPoint" & vbCr & "End Sub") 'Protect the worksheet ActiveSheet.Protect "PASSWORD", DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub The UnprotectVBProj called above looks like this: Sub UnprotectVBProj() Dim Pwd As String Dim vbProj As Object Set vbProj = ActiveWorkbook.VBProject If vbProj.Protection < 1 Then Exit Sub ' already unprotected Set Application.VBE.ActiveVBProject = vbProj SendKeys Pwd & "PASSWORD" & "{Enter}" & "{Enter}" Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute SendKeys "{Enter}" End Sub I'm thinkning it's a compiler problem, like the worksheet VB codepane doesn't recognize the new macro "MAJORtoPowerPoint" being called as part of the code being added. Any help would be greatly appreciated. Terry EggHeadCafe.com - .NET Developer Portal of Choice http://www.eggheadcafe.com |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Worksheet Protection Question | Excel Discussion (Misc queries) | |||
Worksheet protection question | Excel Discussion (Misc queries) | |||
A Worksheet Protection Question | New Users to Excel | |||
Excel97 - Worksheet Protection Question | Excel Programming | |||
question about worksheet protection using userinterfaceonly:=true | Excel Programming |