注意:' Application.Run(" Bringrestover")是之后添加的东西,我重新打开屏幕更新以尝试解决问题。我知道我的代码很糟糕,但我仍然是新的相对论。但在其他宏上,这种格式一直有效 欢迎任何帮助。
感谢
Sub UpdateContracts()
'Application.ScreenUpdating = False
'open the updated and new data
Dim updatedfileo As Workbook
Dim updatedfile As Excel.Worksheet
Dim Filename2 As String
Dim Path2 As String
Path2 = "C:\Users\ki71wo\Desktop\ContractUpdates\UPDATES\UPDATEDFILE\"
Filename2 = Dir(Path2 & "*.XLS")
Set updatedfileo = Workbooks.Open(Path2 & Filename2)
Set updatedfile = Workbooks(Filename2).ActiveSheet 'updates
'set variables
Dim wbk As Workbook
Dim Filename As String
Dim Path As String
Path = "C:\Users\ki71wo\Desktop\ContractUpdates\"
Filename = Dir(Path & "*.xlsx")
updatedfile.Activate
'format updates sheet
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Rows("1:3").Select
Selection.Delete Shift:=xlUp
Rows("2:2").Select
Selection.Delete Shift:=xlUp
j = updatedfile.UsedRange.Rows.Count 'Get the last used row of the first worksheet.
Range("J2").Select
ActiveCell.FormulaR1C1 = "NU"
Range("J2").Select
Selection.AutoFill Destination:=Range("J2:J" & j)
'open master data records
'Do While Len(Filename) > 0 'IF NEXT FILE EXISTS THEN
Do While Filename <> "" 'IF NEXT FILE EXISTS THEN
Set wbk = Workbooks.Open(Path & Filename)
Application.Run ("Ineedtoupdate")
wbk.Close True
Filename = Dir
Loop
' Application.Run ("Bringrestover")
' Application.ScreenUpdating = True
End Sub