ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cannot get Auto_Open or Private Sub Workbook_Open() to run at star (https://www.excelbanter.com/excel-programming/315062-cannot-get-auto_open-private-sub-workbook_open-run-star.html)

Paul Moles

Cannot get Auto_Open or Private Sub Workbook_Open() to run at star
 
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



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

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