VBA有参数时找不到我的宏

VBA有参数时找不到我的宏

本文介绍了VBA有参数时找不到我的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个宏,该宏将附加到Office 2010后台选项卡中的一系列按钮上.根据所单击的按钮,应使用不同的参数调用宏.

I am trying to write a macro that will be attached to a series of buttons in an Office 2010 backstage tab. Depending on the button clicked the Macro should be called with different parameters.

我遇到的问题是,如果将宏定义为具有参数,则VBA将显示宏"对话框,其中未列出宏.从声明中删除参数将允许宏运行,但是需要使宏有意义.

The issue I am having is that if the Macro is defined as having parameters then VBA will display the "Macros" dialog box, with no Macros listed. Removing the parameters from the declaration will allow the macro to run, but it needs the Macros to make sense.

正在使用的VBA如下:

The VBA being used is below:

Sub NewDocs(docType As String, docTemplate As String)
   Dim sMyShellCommand As String
   sMyShellCommand = "C:\NewDocs.exe " & docType & docTemplate
   WordBasic.Shell (sMyShellCommand)
End Sub

任何想法

推荐答案

如果您的问题正确无误....

If I've got your question right....

由于对话框中没有用于输入参数的位置,因此根本不显示带有参数的宏.

Because there is no place in the Macros dialog box for entering parameters, the macros with parameters are simply not shown.

如果要在对话框中显示它们,可以枚举所需的功能(我希望这不是一个大数目).

If you want to make them visible in the dialog box, you can enumerate those functions you need (and I hope it is not a big number).

例如,

Sub NewDocs1
  Dim docType As String
  Dim docTemplate As String

  docType = "the type you want"
  docTemplate = "the template you want"

  NewDocs docType, docTemplate
End Sub

此外,正如您在问题中说的那样,您希望宏在按下按钮时运行.这样就无需使该宏在对话框中可见(这样可以节省您的工作量).只需将其与具有正确参数的按钮关联即可.

In addition, as you said in the question, you wanted the macro to run when buttons were pressed. Then there is no need to make the macro visible in the dialog box (which saves your labor). Simply associate it with the button with correct parameters.

这篇关于VBA有参数时找不到我的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:45