以下代码做为一个自定义函数,执行的时候报错:被呼叫方拒绝接收呼叫见截图
此主题相关图片如下:333337.jpg

Dim path As String = args(0)
Dim excelApp As New MSExcel.Application
excelApp.visible =True
excelApp.DisplayAlerts=False
Dim wordApp As New MSWord.Application
wordapp.Visible = True
Dim Doc As MSWord.Document
Dim DocRange As MSWord.Range
Doc = wordApp.Documents.Add()
Docrange = Doc.range()
Dim filename As String = path & "\统计.docx"
For Each file As String In FileSys.GetFiles(path)
If file.EndsWith(".xls") OrElse file.EndsWith(".xlsx") Then
Dim Wb As MSExcel.WorkBook=excelApp.WorkBooks.open(file)
For k As Integer = 1 To Wb.WorkSheets.Count '//多个sheet的处理
Dim Ws As MSExcel.WorkSheet=Wb.WorkSheets(k)
Dim Rg As MSExcel.Range = Ws.UsedRange
If Rg.Columns.Count <> 16384 Then
Rg.copy()
DocRange.Paste
Docrange.Collapse(0)
Docrange.Insertparagraphafter()
Docrange.Collapse(0)
Else
Dim txt2 As WinForm.TextBox = Forms("EXCEL导WORD").Controls("TextBox6")
txt2.text = file & vbcrlf & txt2.text & vbcrlf
End If
Next
wb.close()
Dim txt1 As WinForm.TextBox = Forms("EXCEL导WORD").Controls("TextBox3")
txt1.text = file & vbcrlf & txt1.text & vbcrlf
Application.DoEvents()
FileCount=FileCount+1
End If
Next
For Each p As String In FileSys.GetDirectories(path)
Functions.Execute("EXCEL导WORD函数", p)
Next
Doc.saveas(filename)
Doc.close()
excelapp.quit()
wordapp.quit()
Dim lbl As WinForm.Label = Forms("EXCEL导WORD").Controls("Label6")
lbl.Text="共处理" & FileCount & "个文件"