这两个代码不能同时运行。怎么样? 我的课程模块代码
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
答案 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