简体   繁体   中英

I have a function in excel VBA which takes input from user using textbox

I have written a macro that takes input from user and returns a cell data. Is there any way that triggers the process to run from macro That is the the inputbox opens up directly with one click without having to go to VBA and run it?

Put this in Worksheet code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call showMsg
End Sub

Put this in your module:

Sub showMsg()
Dim data As String
data = InputBox("Hello", "Title")
End Sub

You can use other worksheet or workbooks events as well eg (It will run macro whenever you open file)

  Private Sub Workbook_Open()
    Call showMsg
  End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM