Help edit code select folder not input path directory

Nguyen Anh Dung

Board Regular
Joined
Feb 28, 2020
Messages
127
Office Version
  1. 2016
Platform
  1. Windows
help edit code when run use mouse select folder not input directory folder as below:
Const strSOURCE_DIR = "d:\Image_SoNha\"
Const strTARGET_DIR = "d:\Image_SoNha\"

Code:
Public Sub MoveImages()
 Const strSOURCE_DIR = "d:\Image_Goc\"
 Const strTARGET_DIR = "d:\Image_SoNha\"
  
Dim strSourcePath As String
  Dim strTargetPath As String
  Dim strSubfolder As String
  Dim strFilename As String
  Dim strMessage As String
  Dim strErrors As String
  Dim lngCounter As Long
                

  On Error GoTo ErrHandler
  strFilename = Dir(strSOURCE_DIR & "*.jpg")
    Do While strFilename <> ""
    strSourcePath = strSOURCE_DIR & strFilename
    strSubfolder = strTARGET_DIR & "20200914_13_" & Mid(strFilename, 2, 3) & "_GoVap_D_01" 'D: Duong, H: Hem, 01: Di,02 Ve: tu sua
    strTargetPath = strSubfolder & "\" & strFilename
    
  ' tao folder neu k ton tai
    On Error Resume Next
    MkDir strSubfolder
    If Err.Number <> 0 Then Err.Clear
  
  ' cat qua thu muc moi
    Name strSourcePath As strTargetPath
    
  ' If an error occurred, log it to error list
    If Err.Number <> 0 Then
      If strErrors <> "" Then strErrors = strErrors & ", "
      strErrors = strErrors & strFilename
    Else
      lngCounter = lngCounter + 1
    End If
    
  ' Move onto next jpg file
    On Error GoTo ErrHandler
    strFilename = Dir()
  Loop
  
' Notify user of results, including any errors
  strMessage = "Transfer of " & lngCounter & " files was completed."
  If strErrors <> "" Then
    strMessage = strMessage & vbCrLf & vbCrLf
    strMessage = strMessage & "These files were unsuccessful:"
    strMessage = strMessage & vbCrLf & strErrors
  End If
  MsgBox strMessage, vbInformation
  Exit Sub
  
ErrHandler:
  MsgBox Err.Description, vbExclamation
End Sub
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Watch MrExcel Video

Forum statistics

Threads
1,126,931
Messages
5,621,661
Members
415,849
Latest member
PhoenixRising2015

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top