如何在一个模块中运行两个应用程序

时间:2018-08-20 01:37:59

标签: excel vba excel-vba

这两个代码不能同时运行。怎么样? 我的课程模块代码

Private sub-App_workbooknewsheet (byval wb as workbook, byval sh as object)
Application.Run "PERSONAL.XLSB!Open_It"
Application.Run "PERSONAL.XLSB!Change"
End sub

Open_it

   Sub Open_it()
' Open the workbook from its actual folder
    Application.ScreenUpdating = False
    Workbooks.Open Filename:="C:\Users\ASUS User\Desktop\MP\source.xlsm", UpdateLinks:=True, ReadOnly:=True
    ActiveWindow.Visible = False
    ThisWorkbook.Activate
    Application.ScreenUpdating = True
End Sub

更改

 Sub Change()
    Columns(2).AutoFit
    Rows().AutoFit
End Sub

1 个答案:

答案 0 :(得分:0)

您使它变得太难了。您只需要一个宏即可遍历source.xlsm

中的所有工作表
Dim ws As Worksheet

Application.DisplayAlerts = False

Workbooks.Open Filename:="C:\Users\ASUS User\Desktop\MP\source.xlsm", UpdateLinks:=True, ReadOnly:=True
    For Each ws In ActiveWorkbook.Worksheets
        ws.Columns(2).AutoFit
        ws.Rows().AutoFit
    Next

Application.DisplayAlerts = False