Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2021, 01:59 PM
coffent coffent is offline Sub Auto_Open() runs but doesn't always work Windows 10 Sub Auto_Open() runs but doesn't always work Office 2019
Advanced Beginner
Sub Auto_Open() runs but doesn't always work
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default Sub Auto_Open() runs but doesn't always work

I have the following subroutine

VBAProject (PERSONAL.xlsb)
Modules
Module1
Sub Auto_Open()
Dim Shortcut As CommandBar
Dim NewItem As CommandBarButton
Set Shortcut = Application.CommandBars("Cell")
Set NewItem = Shortcut.Controls.Add()
With NewItem
Caption = "Insert C Comment"
OnAction = "AddComment"
End With
MsgBox ("Test")
End Sub
which should add a new item to the right click/context menu titled "Insert C Comment", which when clicked, calls the subroutine AddComment() (also stored in Module1).



If I run the routine with Excel already open, everything works as expected. However, if I initially open Excel, my understanding is that a subroutine named Auto_Open stored as above should run automatically. And indeed it does, as evidenced by the test MsgBox being displayed. However recently even though the subroutine runs, "Insert C Comment" is *not* added to the context menu. Some time ago it was inserted ok, and later it was inserted twice(!), but now it's not inserted at all. Any ideas as to what's going on?
Reply With Quote
  #2  
Old 05-08-2021, 04:50 PM
coffent coffent is offline Sub Auto_Open() runs but doesn't always work Windows 10 Sub Auto_Open() runs but doesn't always work Office 2019
Advanced Beginner
Sub Auto_Open() runs but doesn't always work
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default

The subroutine should read
...
.Caption = "Insert C Comment"
.OnAction = "AddComment2"
that is, with "." before Caption & OnAction. (My actual subroutine has it correct.)


(Is there a way for the original poster to edit his post, rather than have to "reply" to it as I've done?) [Note added later: I see I'm able to edit this reply, but not my original post. Don't understand why.]

Last edited by coffent; 05-09-2021 at 09:24 AM. Reason: Add info.
Reply With Quote
  #3  
Old 05-11-2021, 09:41 AM
coffent coffent is offline Sub Auto_Open() runs but doesn't always work Windows 10 Sub Auto_Open() runs but doesn't always work Office 2019
Advanced Beginner
Sub Auto_Open() runs but doesn't always work
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default

The problem has become moot. I'd like to delete the question entirely but can't find how to do it.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA script runs once but if I try to run it again, it does not work jakecahill Excel Programming 3 07-11-2017 07:32 AM
Sub Auto_Open() runs but doesn't always work VBA runs I then save as to keep master free from editds but does not work dingar Word VBA 3 04-27-2017 03:18 PM
SHIFT+END doesn't work derohanes Excel 2 09-28-2015 09:31 AM
Sub Auto_Open() runs but doesn't always work HelpViewer doesn't work dherr Office 1 03-27-2015 07:44 AM
Sub Auto_Open() runs but doesn't always work alt+numeric doesn't work Kungen Word 3 12-02-2011 11:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft