LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Narrowing down the problem

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
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
Worksheet Protection Question Pat Excel Discussion (Misc queries) 1 February 4th 09 11:14 PM
Worksheet protection question Dominic Excel Discussion (Misc queries) 3 August 17th 07 07:46 PM
A Worksheet Protection Question PA New Users to Excel 1 December 8th 06 09:44 AM
Excel97 - Worksheet Protection Question Russell Plummer Excel Programming 2 February 18th 04 04:17 PM
question about worksheet protection using userinterfaceonly:=true David Brisco Excel Programming 0 February 9th 04 09:25 PM


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