|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub Main()
Dim spath, fn, sht As Worksheet, sSht As Worksheet, wb As Workbook
Dim shtName, d, firstCellAdr$, lastCellAdr$
Set d = CreateObject("scripting.dictionary")
d("工行") = "A2"
d("建行") = "A1"
d("交行") = "A2"
d("农行") = "A3"
d("招行") = "A13"
d("中行") = "A9"
spath = ThisWorkbook.Path & "\数据源\"
fn = Dir(spath & "*.xls*")
Do While fn <> ""
shtName = Left(fn, InStrRev(fn, ".") - 1)
For Each sht In Sheets
If sht.Name = shtName Then
sht.Activate
Range("F1:XFD" & Rows.Count).ClearContents
If d.exists(Left(fn, 2)) Then
firstCellAdr = d(Left(fn, 2))
Set wb = Workbooks.Open(spath & fn)
Set sSht = wb.Sheets(1)
lastCellAdr = sSht.Cells.SpecialCells(xlCellTypeLastCell).Address
sSht.Range(firstCellAdr, lastCellAdr).Copy sht.[f1]
wb.Close False
End If
Exit For
End If
Next
fn = Dir()
Loop
End Sub
|
|