|
楼主 |
发表于 2024-3-14 17:19
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
大神,以下是我搜到的其它代码,他多个功能,就是运行这个提取程序后,自动弹窗让选择需要提取的文件夹路径,能否帮忙加到你的代码中,感谢~
Sub 批量复制()
Dim strFolder$, intRowCnt%, wbTarget As Workbook
Dim intRowEnd%, intRowPaste%
Dim intRowsCnt%
Dim ExcelFile$
Application.ScreenUpdating = False
intRowPaste = 1
strFolder = GetPath()
If strFolder <> "" Then
ExcelFile = Dir(strFolder & "\*.xls*")
Do Until ExcelFile = ""
Set wbTarget = Workbooks.Open(strFolder & "\" & ExcelFile)
intRowsCnt = wbTarget.Sheets(1).[E65535].End(xlUp).Row
wbTarget.Sheets(1).Range("D1:E" & intRowsCnt).Copy ThisWorkbook.Sheets(1).Cells(intRowPaste, "A")
intRowPaste = intRowPaste + intRowsCnt
wbTarget.Close False
ExcelFile = Dir
Loop
End If
Application.ScreenUpdating = True
End Sub
Private Function GetPath() As String
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "选择文件夹", 0, 0)
If Not objFolder Is Nothing Then
GetPath = objFolder.self.Path
Else
GetPath = ""
End If
Set objFolder = Nothing
Set objShell = Nothing
End Function
Sub 批量复制_不打开工作簿()
Dim strFolder$, intRowCnt%, wbTarget As Workbook
Dim intRowEnd%, intRowPaste%
Dim intRowsCnt%
Dim ExcelFile$
Application.ScreenUpdating = False
intRowPaste = 1
strFolder = GetPath()
If strFolder <> "" Then
ExcelFile = Dir(strFolder & "\*.xls*")
With ThisWorkbook.Sheets(1)
Do Until ExcelFile = ""
intRowEnd = 1
Do
.Cells(intRowPaste, "A").Formula = "='" & strFolder & "\[" & ExcelFile & "]Sheet1'!$D" & intRowEnd
.Cells(intRowPaste, "B").Formula = "='" & strFolder & "\[" & ExcelFile & "]Sheet1'!$E" & intRowEnd
If .Cells(intRowPaste, "A") <> 0 Or .Cells(intRowPaste, "B") <> 0 Then
.Cells(intRowPaste, "A") = .Cells(intRowPaste, "A").Value
.Cells(intRowPaste, "B") = .Cells(intRowPaste, "B").Value
.Cells(intRowPaste, "C") = "来自:" & strFolder & "\" & ExcelFile
intRowPaste = intRowPaste + 1
intRowEnd = intRowEnd + 1
Else
Exit Do
End If
Loop
ExcelFile = Dir
Loop
End With
End If
Application.ScreenUpdating = True
End Sub
|
|