Learn to run a VBA code and Copy specific files from source folder to destination folder

  Рет қаралды 763

White Board

White Board

3 жыл бұрын

View the comment section of this video

Пікірлер: 2
@rajivranjan-mf6zu
@rajivranjan-mf6zu 11 ай бұрын
@whiteboard3210
@whiteboard3210 3 жыл бұрын
Sub Copyfiles() 'Updateby Extendoffice Dim xRg As Range, xCell As Range Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog Dim xSPathStr As Variant, xDPathStr As Variant Dim xVal As String Dim fso As Object, folder1 As Object Set xRg = Application.InputBox("Please select the file names:", "Excel", ActiveWindow.RangeSelection.Address, , , , , 8) If xRg Is Nothing Then Exit Sub Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker) xSFileDlg.Title = " Please select the original folder:" If xSFileDlg.Show -1 Then Exit Sub xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\" Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker) xDFileDlg.Title = " Please select the destination folder:" If xDFileDlg.Show -1 Then Exit Sub xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\" Call sCopyFiles(xRg, xSPathStr, xDPathStr) End Sub Sub sCopyFiles(xRg As Range, xSPathStr As Variant, xDPathStr As Variant) Dim xCell As Range Dim xVal As String Dim xFolder As Object Dim fso As Object Dim xF As Object Dim xStr As String Dim xFS As Object Dim xI As Integer On Error Resume Next If Dir(xDPathStr, vbDirectory) = "" Then MkDir (xDPathStr) End If For xI = 1 To xRg.Count Set xCell = xRg.Item(xI) xVal = xCell.Value If TypeName(xVal) = "String" And Not (xVal = "") Then On Error GoTo E1 If Dir(xSPathStr & xVal, 16) Empty Then FileCopy xSPathStr & xVal, xDPathStr & xVal End If End If E1: Next xI On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set xFS = fso.GetFolder(xSPathStr) For Each xF In xFS.SubFolders xStr = xDPathStr & "\" & xF.Name Call sCopyFiles(xRg, xF.ShortPath & "\", xStr & "\") If (CreateObject("scripting.FileSystemObject").GetFolder(xStr).Files.Count = 0) _ And (CreateObject("scripting.FileSystemObject").GetFolder(xStr).SubFolders.Count = 0) Then RmDir xStr End If Next End Sub
УГАДАЙ ГДЕ ПРАВИЛЬНЫЙ ЦВЕТ?😱
00:14
МЯТНАЯ ФАНТА
Рет қаралды 2,6 МЛН
HAPPY BIRTHDAY @mozabrick 🎉 #cat #funny
00:36
SOFIADELMONSTRO
Рет қаралды 17 МЛН
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 20 МЛН
6 Excel Tools Most Users Never Think to Use (Files Included)
12:34
MyOnlineTrainingHub
Рет қаралды 130 М.
Excel VBA Macro: List All Files (From a Selected Folder)
8:43
greggowaffles
Рет қаралды 9 М.
How to Move Files from one folder to Another Using Batch Script Command
4:53
Sql Training Sessions
Рет қаралды 8 М.
VBA Macro to Copy Data to Another Workbook
10:30
Excel Destination
Рет қаралды 69 М.
How NVIDIA just beat every other tech company
9:20
Mrwhosetheboss
Рет қаралды 1,1 МЛН
VBA to BROWSE & COPY Data from SELECTED File in Excel
10:00
Leila Gharani
Рет қаралды 323 М.
Move files from one folder to another using Excel VBA
7:06
salim edakuni
Рет қаралды 828
VBA Loop Through All Files in a Folder
8:57
EverydayVBA
Рет қаралды 13 М.
УГАДАЙ ГДЕ ПРАВИЛЬНЫЙ ЦВЕТ?😱
00:14
МЯТНАЯ ФАНТА
Рет қаралды 2,6 МЛН