Sayfa Üzerinde Sağ Tıklanan Menü Yapma

Sayfa Üzerinde Sağ Tıklanan Menü Yapma

Sayfa Üzerinde Sağ Tıklanan Menü Yapma isimli içerikte, ilgili işlemin VBA kodları ile nasıl yapacağınızı öğreten bir Hazır Makro Kodu yer almaktadır.

Hazır Kodlar​

VBA:
Private Sub Workbook_Open()
    CreateContextMenu
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
    Application.CommandBars("MyCustomMenu").Delete
    On Error GoTo 0
End Sub
Sub CreateContextMenu()
    Dim ContextMenu As CommandBar
    Dim MenuItem As CommandBarButton

    ' Önceki menüyü kaldır
    On Error Resume Next
    Application.CommandBars("MyCustomMenu").Delete
    On Error GoTo 0

    ' Yeni menüyü oluştur
    Set ContextMenu = Application.CommandBars.Add(Name:="MyCustomMenu", Position:=msoBarPopup, Temporary:=True)

    ' Menü öğesi 1
    Set MenuItem = ContextMenu.Controls.Add(Type:=msoControlButton)
    MenuItem.Caption = "Öğe 1"
    MenuItem.OnAction = "MyAction1"

    ' Menü öğesi 2
    Set MenuItem = ContextMenu.Controls.Add(Type:=msoControlButton)
    MenuItem.Caption = "Öğe 2"
    MenuItem.OnAction = "MyAction2"

    ' Menü öğesi 3
    Set MenuItem = ContextMenu.Controls.Add(Type:=msoControlButton)
    MenuItem.Caption = "Öğe 3"
    MenuItem.OnAction = "MyAction3"
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    On Error Resume Next
    Application.CommandBars("MyCustomMenu").ShowPopup
    Cancel = True
    On Error GoTo 0
End Sub

' Öğe 1 için işlem
Sub MyAction1()
    MsgBox "Öğe 1 seçildi!"
End Sub

' Öğe 2 için işlem
Sub MyAction2()
    MsgBox "Öğe 2 seçildi!"
End Sub

' Öğe 3 için işlem
Sub MyAction3()
    MsgBox "Öğe 3 seçildi!"
End Sub

Açıklama​

  • CreateContextMenu prosedürü, "MyCustomMenu" adlı yeni bir sağ tıklama menüsü oluşturur ve üç öğe ekler.
  • Worksheet_BeforeRightClick olayı, sağ tıklama menüsünü gösterir ve Excel'in varsayılan sağ tıklama menüsünü iptal eder.
  • Her bir öğe için (MyAction1, MyAction2, MyAction3), kullanıcı bir menü öğesine tıkladığında çalışacak prosedürler tanımlanmıştır.

Notlar:​

  • Workbook_Open olayı, dosya açıldığında özel sağ tıklama menüsünü oluşturur.
  • Workbook_BeforeClose olayı, dosya kapanırken menüyü temizler.
Bu şekilde, Excel sayfanızda sağ tıklama menüsünü özelleştirebilir ve belirli işlemleri bu menüden hızlıca erişilebilir hale getirebilirsiniz.
 
Benzer Konular Popüler İçerikler Daha Fazlası
Geri
Üst