Macro batch change file name (select folder)

It – Hardware & Software | | 4 views

Compilation method of the macroprogram “renaming macro” which changes the name of the plural files with bundle is introduced with serialization type.With this article of the last time, adding the performance which can appoint folder pass simply, it finishes in the program which it is easier to use.


The problematical point of the renaming macro which it drew up

“Macro of modification of previous file name bundle (file name modification)” with, the program which modifies file name was drawn up.Now, function as a renaming macro was completed, but there is a problem in designation method of folder pass.

First, it is difficult the hand to input folder pass one by one.

The hand it is difficult to input folder pass

Applying time, assuming, that it input, making a mistake, when it inputs, it appoints the folder which does not exist, error occurs.

When you are wrong in folder pass, error occurs

Using “the reference dialogue box of the folder,” solving problem

Then, the folder can be appointed adds the program which utilizes “the reference dialogue box of the folder”.Selecting the folder in this dialogue box, when it clicks “the OK” button, it can acquire the folder pass of the folder which it appoints.

browse for folder dialog box

if this, just click on the folder so, compared with when i was manually enter the folder path, operation makes it easy to. also, if there is no problem, such as typing errors, may not be specified folder does not exist.


browse for folder preparing to use the dialog box

it should be noted, browse for folder to use a dialog box, preparation is required. VBEstart, tool menu references please click.

tool menu references click

displayed references of the dialog box library files that can be referenced in the list of, Microsoft Shell Controls And Automation if a check mark is next to, OK please click the button.

Microsoft Shell Controls And Automation put a check mark in the

Subto write a statement

create a program to retrieve the folder path to copy. the standard module has been described so far the programSublet’s write a statement. the macro name gets the folder path to copy suppose you.

Subwrite a statement

the variable2to declare one

subsequently, the variable2to declare one. 1pawl, Shell the declaration of a variable that contains the object. Shellobject, browse for folder is an object with a method that displays the dialog box. the variable name objShell and, here, As after the New to describe the keyword, we like to be able to use the object at the time you declare a variable.

Newkeyword, variable when you declare an instance of an object (copy) to generate the. this is called early binding.

2pawl, Folder3 the declaration of a variable that contains the object. Folder3object, browse for folder an object that represents a folder that is selected in the dialog box. the variable name objFolder suppose you.

Folder3declare a variable to store the object

browse for folder to display the dialog box

browse for folder to display the dialog box, Shellof object BrowseForFolder use the method. 2string specified in the argument of the nail, as a message browse for folder will be displayed in the dialog box. 1nails and3the argument of the nail 0 please specify the.

BrowseForFoldermethod

BrowseForFoldermethod, browse for folder because it returns the selected folder in the dialog box, this variable objFolder stored in the. when you store the object is, Set please use the statement.

BrowseForFolderthe method’s return value to a variable objFolder stored in the

BrowseForFolderexecution of methods image

here, BrowseForFolderlet’s organize the execution of methods image. gets the folder path to copy is running a macro program, BrowseForFolderwhen the method is executed, to pause the program, browse for folder dialog box is displayed.

browse for folder dialog box is displayed

browse for folder select the folder in the dialog box OK when you click the button, the program will resume, is the selected folderFolder3is returned as an object, variable objFolder are stored in the.

to get the selected folder


mechanism to get the folder path

the selected folder (Folder3object) folder path of the, FolderItem of object Path it will get them using the property. FolderItemto see an object, was obtainedFolder3of object Self can be referenced using the property. and therefore, Folder3object FolderItemobject (Selfreferenced in the property) Pathby following properties and, you will get the folder path.

Itemof objectPathgets the folder path in the properties

folder path obtained from the cellB2because we want to enter the, program to enter will be shown in the figure below.

folder path obtained from the cellB2input to

it should be noted, here, browse for folder of the dialog box canceled when the button is clicked, variable objFolder to Nothing are stored is. in this case, Exit Sub let’s kill the execution of the program is. the program, Ifuse the statement, the processing as shown in the figure below. it should be noted, when comparing an object variable that contains the, = instead of Is please use the keyword.

canceled what happens when the button is clicked

variable that contains the object is required for post-processing

in this, the process is completed the program, the variable that contains the object, Nothing post-processing is required to free the memory containing the. here, 2three variables objShell and objFolder about, enter the post-processing as shown below..

post-processing variable that contains the object

completed a program registered with the button

in this, entering the program to get the folder path to copy has been completed. to create a button to make it easier to run, let’s register the program.

register a macro to create a button

create a program to get the copy destination folder path

program to get the destination folder path, copy the program to copy the folder path, or macro name browse for folder modify the string to be displayed in a dialog box, cell in the cell where you want to enter the folder pathB3you only need to modify the.

program to get the copy destination folder path

also:, create a button, you have created a program.

register a macro to create a button

rename macro extension points

at this, suppose you rename the completion of the macro. at the end, let’s introduce the point can be extended.

Excelextract the file name to the list other than the file
the specification was created this time, the old file name to the listExcelonly those files will be extracted. this, Excelto be able to extract the file name to the list other than the file, create a file list of the programDirin the description of the function’s arguments, wildcard extension is also part of * using the Range(“B2″).Value & “?*.*” please correct to.

to bypass the prompt for a new extension of the file name list
when you enter a file name to the list after rename the new file name, at present, there is trouble also need to enter extension. this, the new list of file names as input only the file name, extension, remove from file name to join the list of the old file name, you may want to process, such as.

create a clear button
it is useful to create a macro that clears the list of folders and files path. the contents of the cell ClearContents method can be cleared by. identify a range of cells where the file list will be a big point.

Incoming search terms:

  • batch macro to rename files in a folder (1)
  • microsoft shell controls and automation extensions (1)