Thanks for the reply again, Graham,
Still on 3. Just to confirm, I would like to rename an Excel file from "Report_2017-09-05-??-??-??.xlsx" [the questions marks being different every day] to "Report_2017-09-05.xlsx". So for the above code I can't put in strName = "Report_2017-09-05-05-46-13.xlsx" as the timestamp at the end will be unknown.
In case anyone reads this post at a later date, the above code for removing the last 2 characters from a file name needs a tiny tweak as it's actually deleting 4 characters. The code should read (no need to have the second "-2" as that appears to remove 2 more characters after already removing 2):
Dim strName As String
Dim strNewName As String: strNewName = ""
Dim strPath As String
Dim strExt As String
Dim strDate As String
strPath = "C:\Path\"
strName = "report_20170831070501.csv"
If InStr(1, strName, "_") > 0 Then
strExt = Right(strName, Len(strName) - InStrRev(strName, Chr(46)) + 1)
strNewName = Left(strName, Len(strName) - Len(strExt) - 2)
strDate = Split(strNewName, "_")(1)
If Len(strDate) = 12 And IsNumeric(strDate) = True Then
strNewName = Left(strNewName, Len(strNewName)) & strExt
End If
Name strPath & strName As strPath & strNewName
End If