Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1639|回复: 0

[习题] VBA综练三

[复制链接]
发表于 2012-6-27 17:43 | 显示全部楼层 |阅读模式
指定目录的汇总文件


Sub 汇总()
Dim x%
Dim stpath$, stname$, st$
Dim bk As Workbook
Range("a4:i30").ClearContents
stpath = ThisWorkbook.Path & "/data/"
stname = Dir(stpath & "*.xls?")
Do While stname <> ""
x = Range("A65535").End(3).Offset(1).Row
st = Split(stname, ".")(0)
If Application.WorksheetFunction.CountIf(Range("b4:b30"), st) = 0 Then
   Set bk = Workbooks.Open(stpath & stname)
   ThisWorkbook.Activate
   Range("g2") = Year(Now)
   Range("i2") = Format(Now(), "yyyy/m/d")
       With bk.Sheets(1)
       Cells(x, 1) = x - 3
       Cells(x, 2) = Split(stname, ".")(0)
       Cells(x, 3) = .Range("c2")
       Cells(x, 4) = .Range("c3")
       Cells(x, 5) = .Range("f5")
       Cells(x, 6) = .Range("c5")
       Cells(x, 7) = .Range("c6")
       Cells(x, 8) = .Range("f6")
       End With
   bk.Close
   End If
stname = Dir
Loop
End Sub

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-4 12:30 , Processed in 0.197700 second(s), 6 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表