㈠ 如何用VBA復制整個文件夾包括子目錄
Sub Files(Path As String, afterPath)
'Path:原文件夾路徑;afterPath:目標文件夾路徑
Dim Spath As String
Set fs = CreateObject("Scripting.FileSystemObject")
Spath = Dir(Path, vbDirectory)
Do While Len(Spath)
If Spath <> "." And Spath <> ".." Then
fs.CopyFolder Path, afterPath
Spath = Dir()
End If
Loop
End Sub
————————————————
版權聲明:本文為CSDN博主「前端小菜鳥007」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_41844140/article/details/103188537
㈡ VBA 在圖片文件夾中,查找文件名包含A列文本的圖片,並復制到指定文件夾
Sub導出圖片()
'先清空目標文件夾
DimFilenameAsString
Shell"cmd/c""del/s/qC:UsersAdministratorDesktop導出的*.jpg"""'用DOS命令刪除輸出文件夾下(包含子文件夾,但不刪除子文件夾)的所有jpg文件
Application.ScreenUpdating=False
DimyAsInteger'y是行
DimFilPathAsString'這個是圖片所在的父文件夾
DimnewfilepathAsString'圖片要復制到這里
DimrngAsRange
DimsAsString
WithSheet1'選擇目標sheet
Fory=2To10'從第2行到10行
FilPath="""D:Dropbox產品jpg"&.Cells(y,1).Text&"*.jpg"""
'用XCOPY命令,復制滿足條件的文件包含子文件夾,同時也會在目標文件夾中建立相同的子文件夾
'FilePath中使用了通配符,假如產品是:A001,則可以復制"A001紅色12cm」,"A001紅色15cm」,"A001黑色12cm」,"A001白色15cm」,
Shell"cmd/c""x/s/y"&FilPath&"C:UsersAdministratorDesktop導出的"""
Next
.Cells(1,1).Select
EndWith
Application.ScreenUpdating=False
EndSub