![]() |
|
|
|
#1
|
||||
|
||||
|
The short answer is no, as you cannot use the colon symbol in a Windows file/folder name. The following will use a period/full stop instead. It will work provided the folder is the only sub folder, or if that subfolder does not begin with 'MICHAEL_'. If you are sure there will only be one subfolder you can remove the name check.
Code:
Option Explicit
Sub Rename_Folder()
Dim oFSO As Object
Dim oFolder As Object
Dim oSubFolder As Object
Dim i As Integer
Dim strPath As String
Dim strSubFolderPath As String
Dim strSubFolderNewName As String
strPath = "D:\MIHAI\DOSARE\BAAR"
strSubFolderNewName = strPath & "\" & "MICHAEL_" & Format(Date, "dd.mm.yyyy_") & _
Format(Time, "HH.MM")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strPath)
For Each oSubFolder In oFolder.SubFolders
If Not oSubFolder.Name Like "MICHAEL_*" Then 'Optional
strSubFolderPath = oSubFolder.Path
Name strSubFolderPath As strSubFolderNewName
Exit For
End If 'Optional
Next oSubFolder
lbl_Exit:
Set oFSO = Nothing
Set oFolder = Nothing
Set oSubFolder = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
Thanks a lot man!
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word 2010 - directory mail merge - two separate group of data in one document
|
htsu | Mail Merge | 2 | 03-07-2016 03:10 PM |
vba code for folder name, subfolder directory, file name & revision times
|
klpw | Excel Programming | 2 | 12-24-2015 12:31 AM |
| Can a macro rename Excel files based on a cellname? | chrisd2000 | Excel Programming | 1 | 06-23-2014 06:50 PM |
| Macro to rename multiple Word file with same suffix | ozil61 | Word VBA | 2 | 05-06-2014 07:36 AM |
Rename Outlook 2003 Contacts Folder
|
sfpermits | Outlook | 6 | 07-21-2010 09:56 AM |