Skip to main content

Conas cnaipe saincheaptha a chur leis an roghchlár cliceáil / comhthéacs ceart in Excel?

Mar a thaispeántar thíos scáileáin scáileáin, is iondúil go gcuireann a lán daoine a bhfeidhmeanna a úsáidtear go minic le roghchlár cliceáil ar dheis Excel d’fhonn na feidhmeanna seo a úsáid go tapa agus gan ach cliceáil amháin sa todhchaí. Tá an t-alt seo ag caint ar chnaipe cód saincheaptha a chur leis an roghchlár cliceáil ar dheis in Excel.

Cuir cnaipe saincheaptha leis an roghchlár comhthéacs in Excel le cód VBA


Cuir cnaipe saincheaptha leis an roghchlár comhthéacs in Excel le cód VBA

Má cheaptar gur chruthaigh tú script VBA darb ainm MyMacro i do Excel, agus anois ní mór duit an fheidhm seo a chur leis an roghchlár comhthéacs chun an cód a rith ach é a chliceáil. Déan mar a leanas le do thoil.

1. Brúigh an Eile + F11 eochracha ag an am céanna chun an Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Sa Microsoft Visual Basic d’Fheidhmchláir fuinneog, cliceáil dúbailte An Leabhar Oibre seo ar chlé tionscadal pána. Agus ansin cóipeáil agus greamaigh an cód VBA thíos sa An Leabhar Oibre seo (Cód) fhuinneog.

Cód VBA: Cuir cnaipe saincheaptha leis an roghchlár comhthéacs in Excel

Private Sub Workbook_Deactivate()
    On Error Resume Next
        With Application
            .CommandBars("Cell").Controls("MyMacro").Delete
        End With
    On Error GoTo 0
End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Dim cmdBtn As CommandBarButton
    On Error Resume Next
        With Application
            .CommandBars("Cell").Controls("MyMacro").Delete
            Set cmdBtn = .CommandBars("Cell").Controls.Add(Temporary:=True)
        End With

        With cmdBtn
           .Caption = "MyMacro"
           .Style = msoButtonCaption
           .OnAction = "MyMacro"
        End With
    On Error GoTo 0
End Sub

nótaí: Sa chód, cuir ceann eile ina áit “MyMacro” leis an ainm Macra a chruthaigh tú i do Excel.

3. Brúigh an Eile + Q eochracha chun imeacht as an Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

Anois agus tú ag filleadh ar chomhéadan Excel, tar éis duit cliceáil ar dheis ar chill, feicfidh tú go gcuirtear an cnaipe nua leis an ainm sonraithe isteach sa roghchlár cliceáil ar dheis mar atá thíos an pictiúr a thaispeántar. Spreagfaidh an cnaipe an Macra comhfhreagrach láithreach.


Earraí gaolmhara:

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
Comments (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Zdravím dokázal byste mi prosím někdo poradit s podobným problémem? Po posledním updatu Office přibyla v excelu po stisknutí pravého tlačítka nad kopírovat a vyjmout volba hledat v nabídkách která mi tam vadí a chtěl bych jí odstranit. Dá se to udělat i obráceně a nějakou funkci odstranit?

děkuji
This comment was minimized by the moderator on the site
Hi Tomáš,
I have not encountered this situation. Can you attach a screenshot to describe the problem you encountered more clearly.
This comment was minimized by the moderator on the site
Bonjour,

Je déterre le sujet car j'ai un soucis, j'ai récupérer un fichier qui m'a remplacé le menu du click droit et je ne sais pas comment revenir au menu par défaut...
Ça a modifier le menu pour n'importe quel fichier excel. J'utilise excel 2016.

Je précise que le fichier coupable a un mot de passe pour accéder à son code VBA. Mot de passe qu’évidemment je ne possède pas..

Merci d'avance pour votre aide !!
This comment was minimized by the moderator on the site
Hi Olivier,
Sorry I don't quite understand what you mean. Do you mean to back to the normal right-clicking menu?
This comment was minimized by the moderator on the site
Thanks
Does that working for all workbooks even after restarting Excel, or only for the selected workbook which saved the macro in?
This comment was minimized by the moderator on the site
Размести код в отдельном модуле, для того чтобы это работало для всех документов
This comment was minimized by the moderator on the site
Hi,
It only works for the workbook which save the macro in. Thank you for your comment.
This comment was minimized by the moderator on the site
Add VBA button to context menu works well. Thanks. How do I add more buttons ? (not good at VBA, hence the question).
This comment was minimized by the moderator on the site
Hi Vic,
The following VBA code can help you solve the problem, please have a try.

Private Sub Workbook_Deactivate()
Dim xArrB As Variant
Dim xFNum As Integer
Dim xStr As String
On Error Resume Next
With Application
xArrB = Array("MyMacro01", "MyMacro02", "MyMacro03")
For xFNum = 0 To UBound(xArrB)
xStr = xArrB(xFNum)
.CommandBars("Cell").Controls(xStr).Delete
Next xFNum
End With
On Error GoTo 0
End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim cmdBtn As CommandBarButton
Dim xArrB As Variant
Dim xFNum As Integer
Dim xStr As String
On Error Resume Next
xArrB = Array("MyMacro01", "MyMacro02", "MyMacro03")
For xFNum = 0 To UBound(xArrB)
xStr = xArrB(xFNum)
With Application
.CommandBars("Cell").Controls(xStr).Delete
Set cmdBtn = .CommandBars("Cell").Controls.Add(Temporary:=True)
End With
With cmdBtn
.Caption = xStr
.Style = msoButtonCaption
.OnAction = xStr
End With
Next xFNum
On Error GoTo 0
End Sub
This comment was minimized by the moderator on the site
This doesn't work for me, I have done exactly the same as the above macro with only one menu, Does it work for anyone else or am I doing something wrong?

Thanks
This comment was minimized by the moderator on the site
Don t work with my Excel 2013
This comment was minimized by the moderator on the site
Hi Yves,I tested this code on Excel 2013 and it works fin. Did you get any error prompt? I need to know more specific about your issue
This comment was minimized by the moderator on the site
Thanks for your answerBut doesn't work on a table. On normal cell is work perfectly.
This comment was minimized by the moderator on the site
Hi yves,The problem is clear now, and I need time to fix it. Please wait. Thank you for your feedback.
This comment was minimized by the moderator on the site
Thanks a lot
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations