0
我有一個名爲「Summary_logic」的Excel表,它打開文件夾列表,每個文件夾都有一個帶有VBA腳本的Excel表。我想調用每個文件夾中的VBA腳本(processR1),並將結果複製到Summary_logic表單中。如何在位於其他文件夾的VBA腳本中調用VBA腳本
'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
'名爲「Summary_logic」片,其打開folders'表無法打開文件夾,即使他們能名單,沒有看到你的代碼,完成上述行爲。總之,不明白你的問題/問題。 – findwindow