LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default crash on close

Thanks Dave for all the help! I am going with corruption and move on with
life! Thanks again for all the help!!

"Dave Peterson" wrote:

I don't understand why you have an option to create the menu inside an option in
that menu (activeateinput is the .onaction for the i&nput routine.

If you discount my confusion, I still don't see anything in your code that runs
when the workbook closes--or when excel closes. You may have an event that
calls one of these routines that calls one of the routines that calls one of the
routines??????

Anyway, you can clean up some of your code by using something like this:

Option Explicit
Sub CreateMenu()

Dim CustBar As CommandBar
Dim oControl As CommandBarControl
Dim ctrl As CommandBarControl

Dim myMacs As Variant
Dim myCaps As Variant
Dim iCtr As Long

Set CustBar = Application.CommandBars("Worksheet Menu Bar")

On Error Resume Next
CustBar.Controls("&Name").Delete
On Error GoTo 0

Set oControl = CustBar.Controls.Add(Type:=msoControlPopup, temporary:=True)

With oControl
.Caption = "&NAME"
End With

myCaps = Array("Simulation #&1", _
"Simulation #&2", _
"Simulation #&3", _
"Simulation #&4", _
"Simulation #&5", _
"Simulation #&6", _
"Simulation #&7", _
"&Introduction", _
"I&nput", _
"&Output", _
"&Clear")

myMacs = Array("Sim1", _
"Sim2", _
"Sim3", _
"Sim4", _
"Sim5", _
"Sim6", _
"Sim7", _
"activateintro", _
"activateinput", _
"donothing", _
"delete_prior")

If UBound(myMacs) < UBound(myCaps) Then
MsgBox "Design error!"
Exit Sub
End If

For iCtr = LBound(myMacs) To UBound(myMacs)
Set ctrl = oControl.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With ctrl
.Caption = myCaps(iCtr)
.OnAction = "'" & ThisWorkbook.Name & "'!" & myMacs(iCtr)
End With
Next iCtr
End Sub

Make sure you put the macro names and the macro captions in the correct order!

Matt wrote:

Hey Dave,
We tried changing the code to the following, and the file didn't crash on
closing. Every subsequent try crashes. Does anything get cached in Excel that
might cause something like that? The memory is cleared too which is weird, so
is something about the form cached between uses regardless of a memory
clearing? Thanks! Sorry for all the dang questions!

This is everything:

================================================== =



Sub activateinput()

Call CreateMenu

UserForm1.Show

End Sub



================================================== =



Sub CreateMenu()

'

'THE DROP-DOWN CODE BEGINS HERE

Dim custBar, oControl

Set custBar = CommandBars("Worksheet Menu Bar")



For Each oControl In custBar.Controls

If oControl.Caption = "&NAME" Then

oControl.Delete

End If

Next

Call CreateMenu2

End Sub



================================================== =



Sub CreateMenu2()



Dim custBar As Object

Set custBar = CommandBars("Worksheet Menu Bar").Controls. _

Add(Type:=msoControlPopup)

With custBar

.Caption = "&NAME"

End With



Call CreateClearMenu



Call SubMenu_Output



Call CreateInputMenu



Call CreateIntroMenu



Call SubMenu_Sim7



Call SubMenu_Sim6



Call SubMenu_Sim5



Call SubMenu_Sim4



Call SubMenu_Sim3



Call SubMenu_Sim2



Call SubMenu_Sim1





End Sub



================================================== =



Sub CreateIntroMenu()

With CommandBars("Worksheet menu bar").Controls("&NAME")

.Controls.Add(Type:=msoControlButton, Befo=1).Caption =
"&Introduction"

.Controls("Introduction").OnAction = "activateintro"

End With

End Sub



================================================== =



Sub CreateInputMenu()

With CommandBars("Worksheet menu bar").Controls("&NAME")

.Controls.Add(Type:=msoControlButton, Befo=1).Caption = "I&nput"

.Controls("Input").OnAction = "activateinput"

End With

End Sub

Sub SubMenu_Output()

Dim newSub As Object

Set newSub = CommandBars("Worksheet menu bar").Controls("&NAME")

With newSub

.Controls.Add(Type:=msoControlPopup, Befo=1).Caption = "&Output"

End With

End Sub



================================================== =



Sub CreateClearMenu()

With CommandBars("Worksheet menu bar").Controls("&NAME")

.Controls.Add(Type:=msoControlButton, Befo=1).Caption = "&Clear"

.Controls("Clear").OnAction = "delete_prior"

End With

End Sub

Sub SubMenu_Sim1()

Dim newSubItem As Object

Set newSubItem = CommandBars("Worksheet menu bar") _

.Controls("&NAME").Controls("Output")

With newSubItem

.Controls.Add(Type:=msoControlButton, Befo=1).Caption = "Simulation
#&1"

.Controls("Simulation #1").OnAction = "Sim1"

End With

End Sub

Sub SubMenu_Sim2()

Dim newSubItem As Object

Set newSubItem = CommandBars("Worksheet menu bar") _

.Controls("&NAME").Controls("Output")

With newSubItem

.Controls.Add(Type:=msoControlButton, Befo=1).Caption = "Simulation

 
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
Excel crash reload close 302blue_eyes Excel Discussion (Misc queries) 5 April 10th 08 01:44 PM
Can I stop the close method in an auto close macro Paul Excel Programming 2 November 17th 06 02:48 PM
In Before Close Sub ActiveWorkBook.Close(False) repeat procedure [email protected] Excel Programming 5 September 26th 06 03:11 PM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM


All times are GMT +1. The time now is 05:26 PM.

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"