Cannot get Auto_Open or Private Sub Workbook_Open() to run at star

P

Paul Moles

I have the following code in ThisWorkbook module of Personal.xls:

Private Sub Workbook_Open()
'Sub Auto_Open ()
Dim NewControl As CommandBarControl
' Assign shortcut to Insert Today on SHIFT+CTRL+D
Application.OnKey "+^{D}", "Module2.Insert_Date"
' Add item to shortcut menu on open
On Error Resume Next
Application.CommandBars("Cell").Controls("Insert Date").Delete
On Error GoTo 0
Set NewControl = Application.CommandBars("Cell").Controls.Add
With NewControl
.Caption = "Insert Date"
.OnAction = "Module2.Insert_Date"
.BeginGroup = True
End With

' Assign shortcut to display Calendar Date on SHIFT+CTRL+C
Application.OnKey "+^{C}", "Module11.OpenCalendar"
' Add item to shortcut menu on open
On Error Resume Next
Application.CommandBars("Cell").Controls("Calendar Date").Delete
On Error GoTo 0
Set NewControl = Application.CommandBars("Cell").Controls.Add
With NewControl
.Caption = "Calendar Date"
.OnAction = "Module11.OpenCalendar"
.BeginGroup = False
End With

End Sub


Adapted from Martin Green web page www.fontstuff.com, however it doesn't
seem to matter whether it is Private Sub Workbook_Open() or Sub Auto_Open ()
it doesn't run when Excel starts up.

However in either case if I Run Sub/UserForm from within VBE it works quite
happily.

Personal.xls appears to be loading Ok as it is visible in the VBE and I can
run other macros that are contained with it from Tools, Macros.

There are no other Auto_Open or Workbook_Open modules.

I have tried putting Sub Auto_Open() as a module but still no luck

Any Suggestions?

Many Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top