2014-05-21 90 views
0

我有一个用户表单在单击按钮时在单独的模块中调用宏。我得到以下错误:“运行时错误'450':错误数量的参数或无效的属性分配”从用户表单调用宏时出错

在故障排除中,我删除了参数,并更改了虚拟宏,我打电话不采取参数,但我得到同样的错误。

Public Sub btnSubmit_Click() 
Dim Description As String 
Dim Priority As String 
If (checkCleared.Value = False) Then 
MsgBox ("Please certify that all sensitive informationhas been removed and then submit") 
Exit Sub 
Else 

'Description = formScreen.txtDesc.Value 
'Priority = formScreen.comboPriority.Value 

'Application.Run ThisOutlookSession!postScreenedEmail(Priority, Description) 
Application.Run ThisOutlookSession!postScreenedEmail 
End If 
End Sub 

在单独的模块:

Public Sub postScreenedEmail() '(Priority As String, Description As String) 
MsgBox ("postScreened") 
'MsgBox ("Priority is: " & Priority & " and Description is " & Description) 
End Sub 

我试图调用宏等的其他方法“呼叫postScreenedEmail()”,但它不能看到宏即可。我的最终目标是抓取用户窗体中的值,并将它们传递给另一个宏,以便它们可以与我正在使用的API一起使用。

编辑:我可能混合了我的术语,这是我正在使用的层次结构(无法与我的代表张贴图片)。话虽这么说,我想只有Application.Run "postScreenedEmail", Priority, Description做呼叫,它改变了什么

-Project1(VbaProject.OTM) 
    -Microsoft Outlook Objects 
    | ThisOutlookSession 
    -Forms 
    | formScreen 
    | 
    -Modules 
    Module1 
+0

'在单独的模块:'如果它在模块中,为什么使用'ThisOutlookSession'?它不应该是'Application.Run“ModuleName!postScreenedEmail”'? – L42

回答

1

尝试:的

call postScreenedEmail 

代替:

Application.Run ThisOutlookSession!postScreenedEmail 

既然你子是公开的,VBA应能够在没有模块引用的情况下找到它。

如果这样工作,再次添加引用(使您的代码更具可读性,特别是对于其他人,因为ckuhn203在注释中指出)并查看它是否中断。如果是这样,那就是问题所在。


编辑:


你确定你正在引用正确的模块?

如果我尝试:

-Project1(VbaProject.OTM) 
    -Microsoft Outlook Objects 
    | ThisOutlookSession 
    -Modules 
    | Module1 

在模块1:

Sub jzz() 
Debug.Print "test" 
End Sub 

和ThisOutlookSession:

Sub test() 
Call Module1.jzz 
End Sub 

它的工作原理。没问题。使用:

Application.Run Module1.jzz 

而不是Call会显示编译错误。

即使是:

Sub test2() 
Call ThisOutlookSession.test 
End Sub 

从模块1的工作,没有任何问题。

你可以运行这么小的测试来尝试获取参考吗?

+2

使用模块参考!想想那些必须维护代码的未来开发者。 – RubberDuck

+0

好点。我的意思是要进行测试。我会在我的答案中加上这一点。 – Jzz

+0

尝试和我得到相同的错误 – worseone

0

试试这个......Application.Run需要一个字符串的程序名称,然后用逗号分隔的参数/参数列表:

Application.Run "Procedure_Name", arg1, arg2, arg3

因此,我认为这应该工作:

Application.Run "ThisOutlookSession!postScreenedEmail", Priority, Description

+0

尝试此抛出:运行时错误'438':对象不支持此属性或方法。我尝试了没有引号,它再次抛出错误450。 – worseone