|
- Sub 刷新资料()
- Dim vDir As Variant, nDir As Integer
- Dim vFile As Variant, nFile As Integer
- Dim vFill As Variant
- Dim nCol As Integer
-
- Application.ScreenUpdating = False
-
- ReDim vDir(1 To 1)
- vDir(1) = ThisWorkbook.Path
- 获取文件夹 vDir, 1
-
- ReDim vFile(1 To 1)
- For nDir = 2 To UBound(vDir)
- 获取文件名 vFile, vDir(nDir)
- Next
-
- If vFile(1) <> "" Then
- ReDim vFill(1 To 3, 1 To 1)
- For nFile = 1 To UBound(vFile)
- With Workbooks.Open(vFile(nFile))
- vDir = .Sheets(1).UsedRange.Value
- .Close False
- End With
- For nDir = 2 To UBound(vDir)
- If vDir(nDir, 3) = "C店" Then
- nFill = nFill + 1
- ReDim Preserve vFill(1 To 3, 1 To nFill)
- For nCol = 1 To 3
- vFill(nCol, nFill) = vDir(nDir, nCol)
- Next
- End If
- Next
- Next
- With Sheets("sheet1")
- .UsedRange.Offset(1).ClearContents
- .[A2].Resize(nFill, 3) = Application.WorksheetFunction.Transpose(vFill)
- End With
- End If
-
- Application.ScreenUpdating = True
- End Sub
- Sub 获取文件夹(vDir As Variant, nSearchDir As Integer)
- Dim sDir As String, nDir As Integer
-
- sDir = Dir(vDir(nSearchDir) & "\*.*", vbDirectory)
- Do While sDir <> ""
- If Not (sDir = "." Or sDir = "..") And GetAttr(vDir(nSearchDir) & "" & sDir) = vbDirectory Then
- nDir = 1 + UBound(vDir)
- ReDim Preserve vDir(1 To nDir)
- vDir(nDir) = vDir(nSearchDir) & "" & sDir
- End If
- sDir = Dir
- Loop
- If nSearchDir < UBound(vDir) Then
- nSearchDir = nSearchDir + 1
- 获取文件夹 vDir, nSearchDir
- End If
- End Sub
- Sub 获取文件名(vFile As Variant, ByVal sDir As String)
- Dim sFile As String
-
- sFile = sDir & "\*.xls*"
- Do While sFile <> ""
- ReDim Preserve vFile(1 To UBound(vFile) - (Trim(vFile(1)) <> ""))
- vFile(UBound(vFile)) = sDir & "" & sFile
- sFile = Dir
- Loop
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|