我相信以下内容展示了您需要做的事情。
我创建了两个工作簿:“TryDup1.xls”和“TryDup2.xls”。
“TryDup1.xls”在一个模块中包含以下代码:
Option Explicit
Sub CtrlDup()
Dim PathCrnt As String
Dim WBookOrig As Workbook
Dim WBookOther As Workbook
Call DupMac(1)
Set WBookOrig = ActiveWorkbook
PathCrnt = ActiveWorkbook.Path & "\"
Set WBookOther = Workbooks.Open(PathCrnt & "TryDup2.xls")
Call Application.Run("TryDup1.xls!DupMac", 2)
Call Application.Run("TryDup2.xls!DupMac", 3)
WBookOther.Close SaveChanges:=False
Call DupMac(4)
End Sub
Sub DupMac(Param As Long)
Debug.Print "TryDup1's DupMac: Param=" & Param
End Sub
“TryDup2.xls”在一个模块中包含以下代码:
Option Explicit
Sub DupMac(Param As Long)
Debug.Print "TryDup2's DupMac: Param=" & Param
End Sub
打开“TryDup1.xls”并执行 CtrlDup() 会导致以下内容输出到即时窗口:
TryDup1's DupMac: Param=1
TryDup1's DupMac: Param=2
TryDup2's DupMac: Param=3
TryDup1's DupMac: Param=4
因此宏 CtrlDup() 可以运行任一版本的宏 DupMac()。