Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA - Disappearing custom menu and custom toolbar

Hi:

I have a wired problem with my Macro I generated, (running in Excel
2000)
This macro is copied to XLStart Folder. and I have this macro
installed on 3 user's computers. However on one of the user, my custom
menu and toolbar disappears from time-to-time:

This is how the process works:

There is an external web base software application user will run and
this software generates their reports in Excel format. So when user
runs reports for multiple accounts, it creates these reports and
loaded in Excel (same layout except different info on each excel file)

This application also has a custom menu, so WHEN USERS SWITCH TO THESE
EXCEL REPORTS, THEY WILL SEE THE CUSTOM MENU FROM THAT APPLICATION AS
WELL AS MY CUSTOM MENU AND TOOLBAR.

Only one user has a problem, NOT DURING THE INITIALLY, only after she
closes few excel reports, then at some point MY CUSTOM MENU AND
TOOLBAR DISAPPEARS TOO.

THE MOST WIRED PROBLEM IS THAT THIS IS NOT CONSISTENT, SOME DAY IT'S
OK AND SOME DAY IT'S NOT. AND THE OTHER 2 USERS HAD NEVER EXPERIENCE
THIS PROBLEM.

This is really wired and I did checked, all the users has the same
excel version.

Here's my code in creating custom menu and custom toolbar, I couldn't
find anything wrong with it, maybe some expert might be, it wouldbe
really helpful if you do.

=====================
Code in ThisWorkBook
=====================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call RemoveCustomMenu
Call Toolbar_OFF
End Sub

Private Sub Workbook_Open()
Call AddCustomMenu
Call Toolbar_ON
End Sub


=======================
Code in My Macro Module
=======================

Public Sub AddCustomMenu()
Call RemoveCustomMenu 'Remove custom menu if already exist
Dim cbWSMenuBar As CommandBar
Dim muCustom As CommandBarControl
Dim iHelpIndex As Integer
'
'Add custom menu to "Worksheet Menu Bar"
'
Set cbWSMenuBar = Application.CommandBars("Worksheet Menu Bar")
iHelpIndex = cbWSMenuBar.Controls("Help").Index
Set muCustom = cbWSMenuBar.Controls.Add(Type:=msoControlPopup,
Befo=iHelpIndex)
With muCustom
.Caption = "&Cus-Macro"
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Run Format Current Report"
.FaceId = 550
.OnAction = "CusMacro.BOMacro"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Reserve for Future Use"
.BeginGroup = True
.FaceId = 1296
.OnAction = ""
End With
End With
End Sub

Public Sub RemoveCustomMenu()
Dim cbWSMenuBar As CommandBar

'
'Remove Custom Menu from "Worksheet Menu Bar"
'
On Error Resume Next
Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
cbWSMenuBar.Controls("Cus-Macro").Delete

End Sub
Sub Toolbar_OFF()
Dim bar As CommandBar

' Delete the Commandbar if it already exists
For Each bar In Application.CommandBars
If bar.Name = cCommandBar Then bar.Delete
Next
End Sub

Sub Toolbar_ON()
Dim bar As CommandBar

Toolbar_OFF

Set bar = Application.CommandBars.Add(Name:=cCommandBar,
Position:=msoBarTop, Temporary:=True)

' Button
With bar.Controls.Add(Type:=msoControlButton)
.FaceId = 550
.Caption = "Cus-Macro"
.Style = msoButtonIconAndCaption
.OnAction = "CusMacro.BOMacro"
End With
CommandBars("Cus-Macro").Visible = True

End Sub


Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default VBA - Disappearing custom menu and custom toolbar

Hi Peter

If you click on the Excel X in the top bar by accident instead of the Workbook X to close a workbook,
the BeforeClose event of your Add-in run and delete all the menu items.

Maybe this is the problem


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Peter" wrote in message om...
Hi:

I have a wired problem with my Macro I generated, (running in Excel
2000)
This macro is copied to XLStart Folder. and I have this macro
installed on 3 user's computers. However on one of the user, my custom
menu and toolbar disappears from time-to-time:

This is how the process works:

There is an external web base software application user will run and
this software generates their reports in Excel format. So when user
runs reports for multiple accounts, it creates these reports and
loaded in Excel (same layout except different info on each excel file)

This application also has a custom menu, so WHEN USERS SWITCH TO THESE
EXCEL REPORTS, THEY WILL SEE THE CUSTOM MENU FROM THAT APPLICATION AS
WELL AS MY CUSTOM MENU AND TOOLBAR.

Only one user has a problem, NOT DURING THE INITIALLY, only after she
closes few excel reports, then at some point MY CUSTOM MENU AND
TOOLBAR DISAPPEARS TOO.

THE MOST WIRED PROBLEM IS THAT THIS IS NOT CONSISTENT, SOME DAY IT'S
OK AND SOME DAY IT'S NOT. AND THE OTHER 2 USERS HAD NEVER EXPERIENCE
THIS PROBLEM.

This is really wired and I did checked, all the users has the same
excel version.

Here's my code in creating custom menu and custom toolbar, I couldn't
find anything wrong with it, maybe some expert might be, it wouldbe
really helpful if you do.

=====================
Code in ThisWorkBook
=====================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call RemoveCustomMenu
Call Toolbar_OFF
End Sub

Private Sub Workbook_Open()
Call AddCustomMenu
Call Toolbar_ON
End Sub


=======================
Code in My Macro Module
=======================

Public Sub AddCustomMenu()
Call RemoveCustomMenu 'Remove custom menu if already exist
Dim cbWSMenuBar As CommandBar
Dim muCustom As CommandBarControl
Dim iHelpIndex As Integer
'
'Add custom menu to "Worksheet Menu Bar"
'
Set cbWSMenuBar = Application.CommandBars("Worksheet Menu Bar")
iHelpIndex = cbWSMenuBar.Controls("Help").Index
Set muCustom = cbWSMenuBar.Controls.Add(Type:=msoControlPopup,
Befo=iHelpIndex)
With muCustom
.Caption = "&Cus-Macro"
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Run Format Current Report"
.FaceId = 550
.OnAction = "CusMacro.BOMacro"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Reserve for Future Use"
.BeginGroup = True
.FaceId = 1296
.OnAction = ""
End With
End With
End Sub

Public Sub RemoveCustomMenu()
Dim cbWSMenuBar As CommandBar

'
'Remove Custom Menu from "Worksheet Menu Bar"
'
On Error Resume Next
Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
cbWSMenuBar.Controls("Cus-Macro").Delete

End Sub
Sub Toolbar_OFF()
Dim bar As CommandBar

' Delete the Commandbar if it already exists
For Each bar In Application.CommandBars
If bar.Name = cCommandBar Then bar.Delete
Next
End Sub

Sub Toolbar_ON()
Dim bar As CommandBar

Toolbar_OFF

Set bar = Application.CommandBars.Add(Name:=cCommandBar,
Position:=msoBarTop, Temporary:=True)

' Button
With bar.Controls.Add(Type:=msoControlButton)
.FaceId = 550
.Caption = "Cus-Macro"
.Style = msoButtonIconAndCaption
.OnAction = "CusMacro.BOMacro"
End With
CommandBars("Cus-Macro").Visible = True

End Sub


Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA - Disappearing custom menu and custom toolbar

Hi Ron:

Thank you for your prompt response, very much appreciated.
In terms of what you had suggested, I doubt that might be the cause.
Here's what I had done after first email, I added a call to
workbook_activate() method. see below...

============================
Private Sub Workbook_Open()
'Call the 'sub' so code is only modified in one place
Workbook_Activate
End Sub

'Workbook_activate is new,
Private Sub Workbook_Activate()
Call AddCustomMenu
Call Toolbar_ON
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call RemoveCustomMenu
Call Toolbar_OFF
End Sub
=================================

Since all the workbook is opened, and when user closes one of the
workbook, it closes and remove the menu, and that remove affect rest of
the open workbook and when user activates the other workbook, there is
no action in Workbook_activate() method before. Here I am adding it,
hopefully it will work when they actives the workbook.

Do you think this will fix the problem?

Thanks
Peter


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
custom toolbar dml Excel Discussion (Misc queries) 1 March 17th 10 02:02 PM
Adding a check mark to the custom made toolbar/menu continue...... aiyer[_59_] Excel Programming 0 September 2nd 04 12:52 AM
Custom Menu return to Excel Menu upon Closing VetcalcReport Excel Programming 2 August 2nd 04 02:59 PM
custom toolbar buttons are saved where? Excel loads twice bymistake and all my custom toolbar buttons get gone!!! Kevin Waite Excel Programming 2 March 3rd 04 03:31 PM
saving toolbar buttons on custom toolbar Paul James Excel Programming 12 August 6th 03 08:28 AM


All times are GMT +1. The time now is 04:33 AM.

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"