宏未显示在运行宏菜单中

时间:2023-02-05 10:35:41

I started learning VBA and I don't understand why some macros copy-pasted from the internet do not show up in the run macro menu (Alt-F8).

我开始学习VBA,我不明白为什么一些从互联网上复制粘贴的宏没有出现在运行宏菜单(Alt-F8)中。

Below there are 2 macros, but only the second one is showing. Why? And how do I fix it?

下面有2个宏,但只有第二个显示。为什么?我该如何解决?

Sub Test1(ByVal Target As Hyperlink)

    '...

End Sub

Sub Test2()

    '...

End Sub

宏未显示在运行宏菜单中 宏未显示在运行宏菜单中

4 个解决方案

#1


1  

Macros with arguments are not available in Macros list because they cannot be run alone instead they are called by another macro by passing the required arguments.

带有参数的宏在宏列表中不可用,因为它们不能单独运行,而是通过传递所需的参数由另一个宏调用。

#2


1  

If a Sub declaration contains parameters it will not show there.

如果Sub声明包含参数,则不会在那里显示。

#3


1  

You cannot call macros that have parameters as you are describing. If you need to have a parameter, you can take it out and then have the user input the value.

您无法调用具有参数的宏。如果需要参数,可以将其取出然后让用户输入值。

Sub Test1()        
    Dim hyperLink As String
    hyperLink = InputBox("Please input hyperlink", "My Parameter")

    '...

End Sub

Alternatively, if the hyperlink is in your document, grab the value from your document instead.

或者,如果超链接位于文档中,请从文档中获取值。

#4


1  

Here are my 5 cents - if you give an optional parameter, you will be able to call the sub routine, even if it will not be shown among the ones which you can chose from.

这是我的5美分 - 如果您给出一个可选参数,您将能够调用子例程,即使它不会显示在您可以选择的子例程中。

Write aaaaTestMe and press Run.

写aaaaTestMe并按Run。

Public Sub aaaaTestMe(Optional lngA As Long = 8)
    Debug.Print lngA
End Sub

#1


1  

Macros with arguments are not available in Macros list because they cannot be run alone instead they are called by another macro by passing the required arguments.

带有参数的宏在宏列表中不可用,因为它们不能单独运行,而是通过传递所需的参数由另一个宏调用。

#2


1  

If a Sub declaration contains parameters it will not show there.

如果Sub声明包含参数,则不会在那里显示。

#3


1  

You cannot call macros that have parameters as you are describing. If you need to have a parameter, you can take it out and then have the user input the value.

您无法调用具有参数的宏。如果需要参数,可以将其取出然后让用户输入值。

Sub Test1()        
    Dim hyperLink As String
    hyperLink = InputBox("Please input hyperlink", "My Parameter")

    '...

End Sub

Alternatively, if the hyperlink is in your document, grab the value from your document instead.

或者,如果超链接位于文档中,请从文档中获取值。

#4


1  

Here are my 5 cents - if you give an optional parameter, you will be able to call the sub routine, even if it will not be shown among the ones which you can chose from.

这是我的5美分 - 如果您给出一个可选参数,您将能够调用子例程,即使它不会显示在您可以选择的子例程中。

Write aaaaTestMe and press Run.

写aaaaTestMe并按Run。

Public Sub aaaaTestMe(Optional lngA As Long = 8)
    Debug.Print lngA
End Sub