Hot to Capitalize a Formatted Date in VBA???

AlexB123

Board Regular
Joined
Dec 19, 2014
Messages
207
Hi all,

I created a little sub to rename and save my daily to do list in a specific folder with a specific name. However, instead of creating a folder named "10.Oct18" I would like it to be "10.OCT18". I tried to wrap "UCase" around the relevant function, but it doesn't work. Ideas?

Code:
Public Sub NewDay()
Application.DisplayAlerts = False
    Dim macroWB As Workbook
    Dim fileName As String
    Dim BaseDir1 As String, BaseDir2 As String, BaseDir3 As String
    
        BaseDir1 = "C:\\Alex\My Documents\ToDo's\"
        BaseDir2 = BaseDir1 & Year(Now()) & "\"
        BaseDir3 = BaseDir2 & Format(Now(), "mm") & "." & UCase(Format(Now(), "mmmyy")) & "\"
        
            Call CheckForPaths(BaseDir1, BaseDir2)
            Call CheckOnePath(BaseDir3)
            
        fileName = BaseDir3 & Format(Now(), "mm.dd.yy") & ".xlsm"
        
            Set macroWB = ThisWorkbook
            
    macroWB.Sheets("ToDo's").Activate
    macroWB.SaveAs fileName, 52
    macroWB.Save
    Set macroWB = Nothing
Application.DisplayAlerts = True
End Sub
Public Sub CheckForPaths(sPath1 As String, sPath2 As String)
    If Len(Dir(sPath1, vbDirectory)) = 0 Then
        MkDir (sPath1)
    End If
                        
    If Len(Dir(sPath2, vbDirectory)) = 0 Then
        MkDir (sPath2)
    End If
End Sub
Public Sub CheckOnePath(sPath3 As String)
    If Len(Dir(sPath3, vbDirectory)) = 0 Then
        MkDir (sPath3)
    End If
                        
End Sub

Any help is appreciated!!!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
UCASE works fine for me.

Note that you updated it here:
Code:
BaseDir3 = BaseDir2 & Format(Now(), "mm") & "." & [COLOR=#ff0000][B]UCase[/B][/COLOR](Format(Now(), "mmmyy")) & "\"
but didn't update it here:
Code:
fileName = BaseDir3 & Format(Now(), "mm.dd.yy") & ".xlsm"
Update the filename variable too and you should be good.
 
Upvote 0
UCASE works fine for me.

Note that you updated it here:
Code:
BaseDir3 = BaseDir2 & Format(Now(), "mm") & "." & [COLOR=#ff0000][B]UCase[/B][/COLOR](Format(Now(), "mmmyy")) & "\"
but didn't update it here:
Code:
fileName = BaseDir3 & Format(Now(), "mm.dd.yy") & ".xlsm"
Update the filename variable too and you should be good.

I renamed my current working folder to test the code ... and it ran fine. LOL.

Thanks for pointing out the problem was "User Error"!!!

:rolleyes:
 
Upvote 0
You could simplify

Code:
BaseDir3 = BaseDir2 & Format(Now(), "mm") & "." & UCase(Format(Now(), "mmmyy")) & "\"

to

Code:
BaseDir3 = BaseDir2 & UCase(Format(Date, "mm\.mmmyy\\"))
 
Upvote 0
You could simplify

Code:
BaseDir3 = BaseDir2 & Format(Now(), "mm") & "." & UCase(Format(Now(), "mmmyy")) & "\"

to

Code:
BaseDir3 = BaseDir2 & UCase(Format(Date, "mm\.mmmyy\\"))

Ooh... I like this! But can you explain what's happening with the Slashdot and double backslash??? Thanks!

Code:
BaseDir3 = BaseDir2 & UCase(Format(Date, "mm\.mmmyy\\"))
 
Upvote 0
Help is your friend:

\Display the next character in the format string. To display a character that has special meaning as a literal character, precede it with a backslash (\). The backslash itself isn't displayed. Using a backslash is the same as enclosing the next character in double quotation marks. To display a backslash, use two backslashes (\\).
Examples of characters that can't be displayed as literal characters are the date-formatting and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, / and :), the numeric-formatting characters (#, 0, %, E, e, comma, and period), and the string-formatting characters (@, &, <, >, and !).
 
Upvote 0

Forum statistics

Threads
1,214,824
Messages
6,121,784
Members
449,049
Latest member
greyangel23

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
Back
Top