Purpose of using sub routines over functions

后端 未结 7 1161
抹茶落季
抹茶落季 2021-02-07 07:38

I\'ve been working with Access for a while now, and although I understand the obvious benefit of a Function over a Sub, been that it can return values as a result, I\'m not sure

7条回答
  •  被撕碎了的回忆
    2021-02-07 08:18

    I found one other difference, at least on Excel but likely other Office apps. If you want to customize the ribbon by adding a button to launch a VB program, when you choose Macros in the "Choose commands from" dropdown menu, it lists any Subs in your code but not Functions. Note that a Private Sub will also be hidden from the customize ribbon selection, as will a Public Function.

    So to summarize, these will be available to add as buttons on the ribbon: Sub, Public Sub

    And these will not be available to add: Function, Public Function, Private Function, Private Sub

提交回复
热议问题