首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在位于其他文件夹的VBA脚本中调用VBA脚本

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

Stack Overflow用户
提问于 2015-12-10 06:13:43
回答 1查看 55关注 0票数 0

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

代码语言:javascript
复制
'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
EN

回答 1

Stack Overflow用户

发布于 2015-12-10 11:55:37

试试下面这行:

代码语言:javascript
复制
Application.Run "'" & MyFolder & "\" & MyFile & "'!" & "processR1"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34189998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档