VBA study notes (3) - VBA study notes folder operations (3) - Folder Actions

Description (2017.3.22):

1. In accordance with blue fantasy VBA80 set video teaching, summary

2. Most can be treated with their own function, but copy the folder need to use the FileSystemObject object, open the folder used shell

Copy the code
Public Sub test1. 1 () 
 2 '1. Analyzing folder exists, dir second parameter is vbDirectory, otherwise only determines whether the file exists 
 3 If Dir (ThisWorkbook.path & "\ 1.docx", vbDirectory) = "" the Then 
 . 4 MsgBox ( "not present") 
 . 5 Else 
 . 6 MsgBox ( "present") 
 . 7 End the If 
 . 8 End Sub 
 . 9 
10 Public Sub test2 () 
. 11 'New folder 2. mkdir 
12 is the mkDir (ThisWorkbook.path & "\ 233" ) 
13 End Sub 
14 
15 Public Sub Test3 () 
16 '3. delete a folder, rmdir, only delete empty folders, if you want to delete all the files must first delete all the files inside the kill 
17 rmDir (ThisWorkbook.path & "\ 233 ") 
18 End Sub 
19 
20 Public Sub Test4 () 
21 is' 4. renaming folders and files, name, this method can not be bracketed
The Name & ThisWorkbook.path 22 is "\ 233" of As ThisWorkbook.path & "\ 23,333,333" 
37 [Public Sub TEST7 () 
38 is'. 7.Copy the folder and all the files inside, use the FileSystemObject, Scripting Runtime first introduced in the Microsoft 
39 'CopyFolder copy the folder, copyfile copy the file, just the path, no file name, but also the way renamed
The Name & ThisWorkbook.path 23 is "\ 1.docx" of As ThisWorkbook.path & "\ 2.docx" 
24 End Sub 
25 
26 is Public Sub Test5 () 
27 '5. The mobile folder name move together, can be connected inside the file 
& ThisWorkbook.path the name 28 "\ 2" of As ThisWorkbook.path & "\. 1 \ 23,333,333" 
29 End Sub 
30 
31 is test6 Public Sub () 
32 '6. the copy files, FileCopy, to bring back the destination file name, However, this can not be replicated folder 
33 is the FileCopy ThisWorkbook.path & "\ 1.docx", ThisWorkbook.path & "\. 1 \ 1.docx" 
34 is      
35 End Sub 
36 
41 is the Set New FSO = the FileSystemObject 
42 is' FSO .CopyFolder ThisWorkbook.path & "\ 2", ThisWorkbook.path & "\1\3"
Dim the FileSystemObject FSO of As 40 
43 is fso.CopyFile ThisWorkbook.path & "\ 1.docx", ThisWorkbook.path & "\. 1 \ 2.docx" 
44 is MsgBox "copied" 
45 End Sub 
46 is 
47 Public Sub test8 () 
48 ' 8. open the folder, shell, really is to open the folder, a pop up window! The second parameter is the number 1 opens and displays, and 2 is open to minimize, maximize the open 3 
49 Shell "Explorer.exe" ThisWorkbook.path & & "\ 1", 1 
50 End Sub
Copy the code

Description (2017.3.22):

1. In accordance with blue fantasy VBA80 set video teaching, summary

2. Most can be treated with their own function, but copy the folder need to use the FileSystemObject object, open the folder used shell

Copy the code
Public Sub test1. 1 () 
 2 '1. Analyzing folder exists, dir second parameter is vbDirectory, otherwise only determines whether the file exists 
 3 If Dir (ThisWorkbook.path & "\ 1.docx", vbDirectory) = "" the Then 
 . 4 MsgBox ( "not present") 
 . 5 Else 
 . 6 MsgBox ( "present") 
 . 7 End the If 
 . 8 End Sub 
 . 9 
10 Public Sub test2 () 
. 11 'New folder 2. mkdir 
12 is the mkDir (ThisWorkbook.path & "\ 233" ) 
13 End Sub 
14 
15 Public Sub Test3 () 
16 '3. delete a folder, rmdir, only delete empty folders, if you want to delete all the files must first delete all the files inside the kill 
17 rmDir (ThisWorkbook.path & "\ 233 ") 
18 End Sub 
19 
20 Public Sub Test4 () 
21 is' 4. renaming folders and files, name, this method can not be bracketed
The Name & ThisWorkbook.path 22 is "\ 233" of As ThisWorkbook.path & "\ 23,333,333" 
37 [Public Sub TEST7 () 
38 is'. 7.Copy the folder and all the files inside, use the FileSystemObject, Scripting Runtime first introduced in the Microsoft 
39 'CopyFolder copy the folder, copyfile copy the file, just the path, no file name, but also the way renamed
The Name & ThisWorkbook.path 23 is "\ 1.docx" of As ThisWorkbook.path & "\ 2.docx" 
24 End Sub 
25 
26 is Public Sub Test5 () 
27 '5. The mobile folder name move together, can be connected inside the file 
& ThisWorkbook.path the name 28 "\ 2" of As ThisWorkbook.path & "\. 1 \ 23,333,333" 
29 End Sub 
30 
31 is test6 Public Sub () 
32 '6. the copy files, FileCopy, to bring back the destination file name, However, this can not be replicated folder 
33 is the FileCopy ThisWorkbook.path & "\ 1.docx", ThisWorkbook.path & "\. 1 \ 1.docx" 
34 is      
35 End Sub 
36 
40 Dim FSO the FileSystemObject of As 
41 is the Set New FSO = the FileSystemObject 
42 is' FSO .CopyFolder ThisWorkbook.path & "\ 2", ThisWorkbook.path & "\1\3"
43 is fso.CopyFile ThisWorkbook.path & "\ 1.docx", ThisWorkbook.path & "\. 1 \ 2.docx" 
44 is MsgBox "copied" 
45 End Sub 
46 is 
47 Public Sub test8 () 
48 ' 8. open the folder, shell, really is to open the folder, a pop up window! The second parameter is the number 1 opens and displays, and 2 is open to minimize, maximize the open 3 
49 Shell "Explorer.exe" ThisWorkbook.path & & "\ 1", 1 
50 End Sub
Copy the code

Guess you like

Origin www.cnblogs.com/medik/p/10989727.html