怎么用VBA,把一个Excel里的部分区域复制到指定文件夹里的每个工作簿里的每个工作表里的每个指定单元格
请查看附件案例,【程序所在表】和【测试文件夹】在相同文件夹里,我想通过按【程序所在表】里的按钮,把C1到D4区域复制到【测试文件夹】里的每个工作簿里的每个工作表里的每个【...
请查看附件案例,【程序所在表】和【测试文件夹】在相同文件夹里,我想通过按【程序所在表】里的按钮,把C1到D4区域复制到【测试文件夹】里的每个工作簿里的每个工作表里的每个【总计】的右边一个单元格,请问要怎么编写程序啊?
展开
展开全部
答:
Sub CopyToFile()
Dim Wb As Workbook, sFile As String
Dim Rng As Range, C As Range
Dim FirstAddress As String
Dim Sht As Worksheet
sPath = ThisWorkbook.Path & "\测试文件夹\"
sFile = Dir(sPath & "*.xls*")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Rng = Sheets("名字1").Range("C1:D4")
Do While sFile <> ""
Set Wb = Workbooks.Open(sPath & sFile)
For Each Sht In Wb.Worksheets
With Sht
Set C = .UsedRange.Find(what:="总计", lookat:=xlWhole)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
Rng.Copy C.Offset(0, 1)
Set C = .UsedRange.FindNext(C)
Loop While Not C Is Nothing And C.Address <> FirstAddress
End If
End With
Next Sht
Wb.Close savechanges:=True
sFile = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |