0

I am using excel and learning how to code in vba for macro buttons.

I was trying to create button and put a code so that when I double click on the button vba window gets open instead of using shortcut alt+f11.

Can anyone please provide any details if there is any code ? Thanks

Plutian
  • 2,276
  • 3
  • 14
  • 23

1 Answers1

2

This will do it:

Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Application.VBE.MainWindow.Visible = True
End Sub

Put this in the sheet object your button is on.

Plutian
  • 2,276
  • 3
  • 14
  • 23
  • How to implement this for double click ? – user3102147 Oct 14 '19 at 10:26
  • It gives error program access to vba is not trusted how can O fix that ? – user3102147 Oct 14 '19 at 10:33
  • Now it gives compile error: user-defined type not defined. Also it opens in single click – user3102147 Oct 14 '19 at 10:41
  • This has to do with your vba trust settings. [this answer](https://stackoverflow.com/questions/25638344/programmatic-access-to-visual-basic-project-is-not-trusted) should help you sort that out. – Plutian Oct 14 '19 at 10:44
  • @user3102147 If it doesn't work, it will throw an error right away, opening the window automatically. This is due to the error, not the code. Have you added anything to the single click module of your code? – Plutian Oct 14 '19 at 10:45
  • I have only copy pasted the code which you have mentioned and it gives compile error: User-defined type not defined – user3102147 Oct 14 '19 at 10:50
  • It is might be becuase of MsForms because when I type the code I don’t see any of these option as I am working on sheet in excel not on forms – user3102147 Oct 14 '19 at 10:52
  • If you open your vba window, click tools > References and check if your `Microsoft Forms 2.0 Object Library` is selected as it should be. – Plutian Oct 14 '19 at 10:59