ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   custom menu items not responding after initial save (https://www.excelbanter.com/excel-programming/362899-custom-menu-items-not-responding-after-initial-save.html)

MAB

custom menu items not responding after initial save
 
After saving a workbook created from a template with marcos (BOM
importation), the custom right click menu items I create error out. It seems
if you don't save the file using the default name then the menu error occurs.


MAB

custom menu items not responding after initial save
 
Here's the code for the menu creation

Private WithEvents xlApp As Excel.Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)

'Add or remove Hyperlink menu items based on whether or not Hyperlink(s)
are selected

Dim oCtrl As CommandBarControl
Dim oBtn As CommandBarControl
Dim bMenusExist As Boolean
Dim bHyperlinksExist As Boolean

For Each oCtrl In Application.CommandBars("Cell").Controls
If oCtrl.Caption = "Copy Hyperlinked Docs To..." Then
bMenusExist = True
Exit For
End If
Next

bHyperlinksExist = Target.Hyperlinks.Count 0

If bHyperlinksExist And Not bMenusExist Then
Set oCtrl =
Application.CommandBars("Cell").Controls.Add(Type: =msoControlButton, _
Temporary:=True)
oCtrl.Caption = "Copy Hyperlinked Docs To..."
oCtrl.OnAction = "CopyHyperlinkedDocsTo"

Set oCtrl =
Application.CommandBars("Cell").Controls.Add(Type: =msoControlButton, _
Temporary:=True)
oCtrl.Caption = "Zip && Email Hyperlinked Docs..."
oCtrl.OnAction = "ZipAndEmailHyperlinkedDocs"
ElseIf Not bHyperlinksExist Then
For Each oCtrl In Application.CommandBars("Cell").Controls
If oCtrl.Caption = "Copy Hyperlinked Docs To..." Then
oCtrl.Delete
ElseIf oCtrl.Caption = "Zip && Email Hyperlinked Docs..." Then
oCtrl.Delete
End If
Next
End If
End Sub

"MAB" wrote:

After saving a workbook created from a template with marcos (BOM
importation), the custom right click menu items I create error out. It seems
if you don't save the file using the default name then the menu error occurs.



All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com