【笔记】在模块2中,调用模块1中的函数selectBooks
模块2:跨模块调用模块1函数 selectBooks
-----------------------------------------------------------------------
Sub bookIn()
Dim v As Object
Set v = 模块1.selectBooks 'v 用于接收跨模块函数的返回值
End Sub
模块1:
1. 若想让调用者接收到函数的返回值,被调用的“跨模块函数”必须抛出返回值;
2. 若不抛出返回值,函数可被调用,但调用者无法接收到返回值,适用于无需返回值的操作
-----------------------------------------------------------------------
Public Function selectBooks() As Object
Dim bk, dic_bk as Object
Set dic_bk = CreateObject("Scripting.Dictionary")
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
If .Show = -1 Then '0:未选文件
For Each bk In .SelectedItems
arr = Split(bk, "\"): n = UBound(arr): arr = Split(arr(n), "."): bkName = arr(0)
dic_bk.Add (bk), bkName
Next: Set selectBooks = dic_bk '抛出函数的返回值(可供跨模块/甚至跨文件调用)
End If
End With
End Function