在Excel VBA中调用函数时无效的过程调用或参数

徐活

单击时,有一个命令按钮可以触发向客户发送电子邮件的触发器。它将首先这样调用该函数:

Private Sub Lotus2_Click()
ThisWorkbook.Send_Unformatted_Rangedata (2)
End Sub

然后在另一个工作表中有两个待调用函数,我无法调试它,因为无论何时,系统只会向我显示调用该函数的行。问题是我知道调用函数有问题,但是我不确定函数的哪一部分出错。很抱歉,功能部分有点繁琐,如下所示。我非常感谢您提供的任何建议,谢谢。

********* UPDATE *******************嗨,我刚发现此行有错误,并显示以下错误消息Run time error -2147417851 (80010105) Automation error The server threw an exception

Set noDocument = noDatabase.CreateDocument

但是我没有发现任何问题。任何帮助将不胜感激。

Sub Send_Unformatted_Rangedata(i As Integer)
Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim vaRecipient As Variant
Dim rnBody As Range
Dim Data As DataObject
Dim rngGen As Range
Dim rngApp As Range
Dim rngspc As Range

Dim stSubject As String
stSubject = "E-Mail For Approval for " + (Sheets("Summary").Cells(i, "A").Value) + "  for the Project  " + Replace(ActiveWorkbook.Name, ".xls", "")
'Const stMsg As String = "Data as part of the e-mail's body."
'Const stPrompt As String = "Please select the range:"

'This is one technique to send an e-mail to many recipients but for larger
'number of recipients it's more convenient to read the recipient-list from
'a range in the workbook.
 vaRecipient = VBA.Array(Sheets("Summary").Cells(i, "U").Value, Sheets("Summary").Cells(i, "V").Value)

On Error Resume Next
'Set rnBody = Application.InputBox(Prompt:=stPrompt, _
     Default:=Selection.Address, Type:=8)
'The user canceled the operation.
'If rnBody Is Nothing Then Exit Sub
Set rngGen = Nothing
Set rngApp = Nothing
Set rngspc = Nothing

Set rngGen = Sheets("General Overview").Range("A1:C30").SpecialCells(xlCellTypeVisible)
Set rngApp = Sheets("Application").Range("A1:E13").SpecialCells(xlCellTypeVisible)

Set rngspc = Sheets(Sheets("Summary").Cells(i, "P").Value).Range(Sheets("Summary").Cells(i, "Q").Value).SpecialCells(xlCellTypeVisible)
Set rngspc = Union(rngspc, Sheets(Sheets("Summary").Cells(i, "P").Value).Range(Sheets("Summary").Cells(i, "R").Value).SpecialCells(xlCellTypeVisible))

 On Error GoTo 0

If rngGen Is Nothing And rngApp Is Nothing And rngspc Is Nothing Then
    MsgBox "The selection is not a range or the sheet is protected. " & _
           vbNewLine & "Please correct and try again.", vbOKOnly
    Exit Sub
End If


'Instantiate Lotus Notes COM's objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")

'Make sure Lotus Notes is open and available.
 If noDatabase.IsOpen = False Then noDatabase.OPENMAIL

'Create the document for the e-mail.
Set noDocument = noDatabase.CreateDocument

'Copy the selected range into memory.
rngGen.Copy
rngApp.Copy
rngspc.Copy

'Retrieve the data from then copied range.
Set Data = New DataObject
Data.GetFromClipboard

'Add data to the mainproperties of the e-mail's document.
With noDocument
  .Form = "Memo"
  .SendTo = vaRecipient
  .Subject = stSubject
  'Retrieve the data from the clipboard.
  .Body = Data.GetText & " " & stMsg
  .SaveMessageOnSend = True
End With

'Send the e-mail.
With noDocument
  .PostedDate = Now()
  .send 0, vaRecipient
End With

'Release objects from memory.
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing


'Activate Excel for the user.
AppActivate "Microsoft Excel"

'Empty the clipboard.
Application.CutCopyMode = False

MsgBox "The e-mail has successfully been created and distributed.", vbInformation

End Sub
尼克失踪

然后在另一张纸上有两个功能部分

如果过程位于工作表模块中,则应使用以下命令调用它们:

Sheet_Object_Name.Send_Unformatted_Rangedata (2)

第二种选择是将过程移至ThisWorkbook模块,然后将您的代码:

ThisWorkbook.Send_Unformatted_Rangedata (2)

应该工作正常。

另一个解决方案是将一个单独的模块添加到您的项目中(使用Insert->Module),在其中移动过程,然后您可以使用以下简单的方法从其他模块中调用这些过程:

Send_Unformatted_Rangedata (2)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

获取下一个文件时,Excel VBA 中的过程调用或参数无效

vba excel条件格式 - 无效的过程调用或参数

Excel:从工作表中调用vba函数时,将当前单元格作为参数传递

将访问查询导入 excel 表时出现“无效的过程调用或参数”

VBA Excel:参数数量错误或调用函数的属性分配无效

Excel VBA调用SQL存储过程(日期参数-无结果!)

从Excel / VBA调用Scala函数

如何使用VBA在Excel中的ENTER键上调用函数

VBA函数在excel中调用时返回#VALUE

从Qt在Excel中调用用户定义的VBA函数

使用参数调用Excel VBA子例程

在VBA函数中使用Application.Match时出现“无效的过程调用或参数”

调用 MergeArea 时过程调用或参数无效

填充 ComboBox 时无效的过程调用或参数 vba

从Excel错误2517调用Access VBA函数

从Excel VBA调用Oracle PL SQL函数

使用Excel VBA从Rust DLL调用函数

Excel VBA 调用函数和循环

VBA 中的无效过程调用和参数错误

从 Excel 调用 Access 函数

在Excel公式中调用VBA类模块

VBA-在Excel中显示的API调用

MDX:减去时无效的过程调用或参数

调用带有对象作为参数的子例程时的运行时错误Excel VBA

在VBA中的excel的特定实例中调用excel宏

使用Excel-DNA,如何将Excel外接函数调用中未指定的参数与丢失的参数区分开?

从Excel调用的Access VBA函数导致返回不同的值

从Excel Vba对DLL函数调用进行故障排除

从Excel使用VBA变量函数调用SQL查询