I have Excel 2003 and I've created an Add-in as well as a seperate workbook w/a module to import the add-in to users "Add-ins" folder on their hard drive. It adds the add-in, but I don't think the "AutoExec" works since the menu item is not appearing on the toolbar
Here's the code for adding the Add-in to user's "Add-ins" folder
And here's the code for the AutoExec:
If you can point me out to the error of my coding I would greatly appreciate it.
Here's the code for adding the Add-in to user's "Add-ins" folder
Code:
Private Const V_Tools_Menu_ID As Long = 30007&
Private Const V_Tag = "CustomViews"
Sub InstallPTMSMacroAddin()
Dim AddinFile As String
Call UnInstallOldAddin
Call DeleteMenuItem
AddinFile = "\\XXX\yyy\zzz\CustomViews.xla"
On Error GoTo ErrorHandler
Application.AddIns.Add AddinFile, True
AddIns("Customviews").Installed = True
msg = MsgBox("Custom views Addin Installed. To activate Addin, use the Add-in manager under the Tools menue to add the checkmark next to 'MOR PTMS Macros'", vbInformation, "Installed!")
Workbooks("Custom_View_Macro_Installer.xls").Close (False)
Exit Sub
ErrorHandler:
msg = MsgBox("Custom View Macro FAILED to install, check to ensure you have network access, and access to the specified shared-drive (" & AddinFile & "), if you continue to have problems, contact Heidi Meade, or your local MOR Owner.", vbCritical, "Error Installing Addin")
End Sub
Sub UnInstallOldAddin()
Dim AddinName As String
On Error Resume Next
AddinName = AddIns("Customviews").FullName
AddIns("Custom Views").Installed = False
AddIns("CustomViews").Installed = False
Kill AddinName
End Sub
Sub DeleteMenuItem()
On Error Resume Next
CommandBars(1).FindControl(ID:=V_Tools_Menu_ID). _
Controls("&Custom Views Buttons").Delete
If CommandBarExists("CustomViews") Then
Application.CommandBars("CustomViews").Delete
End If
End Sub
Private Function CommandBarExists(nname) As Boolean
'Returns TRUE if the range name exists
Dim n As CommandBar
CommandBarExists = False
For Each n In Application.CommandBars
If UCase(n.Name) = UCase(nname) Then
CommandBarExists = True
Exit Function
End If
Next n
End Function
And here's the code for the AutoExec:
Code:
'Option Explicit
'---------------Process Metric Sheet Navigation / Flags Global Variables---------------
Public Schedule 'runs schedule view if true
Public Construction 'runs construction view if true
Public Customview 'runs custom view if true
Public startheader 'starting point for custom view to start
Public msg 'if the customer wants the custom view saved
Public Newsheet 'for the new view
Public Newsheetname 'for the new view
'**************************************
' Global Variables
'**************************************
Public strFA As String ' Used by the Named Range Creator
Public strTool As String ' Used by the Named Range Creator
'
Dim x As New clsView
Private Const V_Tools_Menu_ID As Long = 30007&
Private Const V_Tag = "CustomViews"
Sub StartTrackingEvents()
Set x.XL = Excel.Application
End Sub
Sub StopTrackingEvents()
Set x = Nothing
End Sub
Sub AutoExec()
Dim FName1, FName2, FName3, FName4, FName5
Dim path As String
Dim CurrentSheetName As String
Dim cbrCustomViews As CommandBar
'path = ActiveWorkbook.path
CurrentSheetName = "CustomViews.xls"
'
'
''imports the modules
If CommandBarExists("CustomViews") Then
Application.CommandBars("CustomViews").Delete
End If
Set cbrCustomViews = Application.CommandBars.Add
cbrCustomViews.Name = "CustomViews"
cbrCustomViews.Position = msoBarTop
With cbrCustomViews.Controls
Set cbcSchView = .Add(msoControlButton)
Set cbcConstView = .Add(msoControlButton)
cbcSchView.Caption = "Schedule View"
cbcConstView.Caption = "Construction View"
cbcSchView.DescriptionText = "Click to format Schedule View"
cbcConstView.DescriptionText = "Click to format Construction View"
cbcSchView.Style = msoButtonCaption
cbcConstView.Style = msoButtonCaption
cbcConstView.BeginGroup = True
'call required procedures when buttons clicked for XLA
cbcConstView.OnAction = "CustomViews.xla!Views.Construction_View"
cbcSchView.OnAction = "CustomViews.xla!Views.Schedule_View"
End With
End Sub
Sub AddMenuItem()
Dim ToolsMenu As CommandBarPopup
Dim NewMenuItem As CommandBarButton
'Delete the menu if it already exists
Call DeleteMenuItem
'Find the Tools Menu
Set ToolsMenu = CommandBars.FindControl(ID:=V_Tools_Menu_ID)
If ToolsMenu Is Nothing Then
MsgBox "Cannot add menu item."
Exit Sub
Else
Set NewMenuItem = ToolsMenu.Controls.Add _
(Type:=msoControlButton)
With NewMenuItem
.Caption = "&Custom Views Buttons"
.FaceId = 282
.OnAction = "ResetButtons"
.BeginGroup = True
.Tag = V_Tag
End With
End If
End Sub
Sub DeleteMenuItem()
On Error Resume Next
CommandBars(1).FindControl(ID:=V_Tools_Menu_ID). _
Controls("&Custom Views Buttons").Delete
End Sub
Sub ResetButtons()
Call AutoExec
End Sub
Private Function CommandBarExists(nname) As Boolean
'Returns TRUE if the range name exists
Dim n As CommandBar
CommandBarExists = False
For Each n In Application.CommandBars
If UCase(n.Name) = UCase(nname) Then
CommandBarExists = True
Exit Function
End If
Next n
End Function
If you can point me out to the error of my coding I would greatly appreciate it.