|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub TEST()
Dim strFileName$, strPath$, i&, Rng As Range, rngTarget As Range
Application.ScreenUpdating = False
strPath = ThisWorkbook.Path & "\"
Set rngTarget = [A1].CurrentRegion
strFileName = Dir(strPath & "*.xls*")
Do Until strFileName = ""
If strFileName <> ThisWorkbook.Name Then
With Workbooks.Open(strPath & strFileName)
Set Rng = Nothing
For i = 1 To Len(FName(strFileName))
If Rng Is Nothing Then
Set Rng = rngTarget.Columns(Val(Mid(FName(strFileName), i, 1)) + 1)
Else
Set Rng = Union(Rng, rngTarget.Columns(Val(Mid(FName(strFileName), i, 1)) + 1))
End If
Next i
Rng.Copy .Sheets(1).[B1]
.Close True
End With
End If
strFileName = Dir
Loop
Application.ScreenUpdating = True
Beep
End Sub
Function FName(FileName As Variant) As String
Application.Volatile
FName = Left(FileName, InStrRev(FileName, ".") - 1)
End Function
|
评分
-
2
查看全部评分
-
|