View Single Post
 
Old 10-24-2016, 04:22 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote