如何调用位于其他文件夹中的VBA脚本中的VBA脚本

我有一个名为“Summary_logic”的Excel工作表,它打开文件夹列表,每个文件夹都有一个带有VBA脚本的Excel工作表。 我想调用每个文件夹中的VBA脚本(processR1),并将结果复制到Summary_logic表单中。

'My code is given below. Private Const test_pvt_1_name As String = "TestPVT_Result_template" Private Const pvt_1_range As String = "G7:V1000" Private Const pvt_1_range_testname As String = "C7:C1000" Sub CleanTable() clear_summary delete_auxiliary_sheets Sheets("Summary_logic").Select End Sub ' Deletes all the values in the specified range Private Sub clear_summary() Sheets("Summary_logic").Select 'PVT_R01, Sensitivity Range: Range(pvt_1_range).Select Selection.ClearContents Range(pvt_1_range_testname).Select Selection.ClearContents MsgBox ("Clear_Summary Executed") End Sub ' Delete all sheets except "Summary" Private Sub delete_auxiliary_sheets() For Each wsht In Worksheets If wsht.Name <> "Summary_logic" Then Application.DisplayAlerts = False Sheets(wsht.Name).Delete Application.DisplayAlerts = True End If Next MsgBox ("delete_auxiliary_sheets Executed") End Sub Private Sub open_files() Dim MyFolder As String Dim MyFile As String: MyFile = "TestPVT_Result_template" & ".xlsm" Dim i As Integer i = 1 MsgBox (" Don't forget to enter the path of the PVT folders here") MyFolder = "C:\Users\venkatav\Desktop\vba practice\new code\PVT_2015_10_20" & Application.PathSeparator & Sheets("PVT_test_names1").Range("A1").Cells(i, 1).Value MsgBox (" MyFolder is :") & MyFolder 'returns the folder name MyFile = Dir(MyFolder & Application.PathSeparator & MyFile) MsgBox (" MyFile is :") & MyFile 'returns the TESTPVT_R1_out.csv 'Here I have to open the each .xlsm file and run the macro Workbooks.Open Filename:=MyFolder & "\" & MyFile MsgBox ("Opened the first file in the first folder") 'Now have to call the macro MsgBox ("Calling the macro") 'Here I have to call the macro in other excel file.. need help here Call processR1 'And then the results from the resultant process has to be copied to the summary_logic ranges End Sub 'calls each macro from all the excel files and copies the data 

试试这一行:

 Application.Run "'" & MyFolder & "\" & MyFile & "'!" & "processR1"