以下代码仅返回目标工作簿中的空白,但源工作簿具有值。我相信它出现在" Wkb.Worksheets ...."中。任何指针都非常赞赏。
Sub UpdateAdminBook()
Dim wbSrc As Workbook
Set wbSrc = ActiveWorkbook
Dim MyPath As String
Dim MyFile As String
Dim Wkb As Workbook
Dim Cnt As Long
Application.ScreenUpdating = False
MyPath = "T:\4 - Operating\Tribute at Heritage Village - Manassas VA 1\Community Operations\Department Spend Down Sheets\" 'change the path accordingly
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "Administration.xlsx")
Cnt = 0
Do While Len(MyFile) > 0
Cnt = Cnt + 1
Set Wkb = Workbooks.Open(MyPath & MyFile)
Wkb.Worksheets("Administration").Range("D18:D37").Value = wbSrc.Sheets("Administration").Range("D18:D37") 'change the new value accordingly
Wkb.Close savechanges:=True
MyFile = Dir
Loop
If Cnt > 0 Then
MsgBox "Completed...", vbExclamation
Else
MsgBox "No files were found!", vbExclamation
End If
Application.ScreenUpdating = True
End Sub