Hello everybody .
I am adding the new sheet to existing workbook and the file that is being imported name like this 07-13-11.xls and I would like to name the new sheet as 071311. The below is code that I am able come up so far and it return the name 07-13-11.xls. I am not gof to use InStr Function , please really apreciate for help:
Sub AddWorksheet()
Dim FileName2 As String
Dim Filename1 As String
Dim FileName3 As String
Dim FileName4 As String
Dim FileName5 As String
Dim Year As String
Dim Filename As String
Dim FLName As String
FLName = Application.GetOpenFilename
Dim NewSheet As Worksheet
Filename1 = Right(FLName, 12)
FileName2 = Mid(Filename1, InStr(Filename1, "-") + 8, 12)
FileName3 = Mid(Filename1, InStr(Filename1, "-") + 1, 2)
FileName4 = Mid(Filename1, InStr(Filename1, "-") + 3, 2)
Year = "2011"
FileName5 = FileName3 + "/" + FileName4 + "/" + Year
Worksheets.Add().Name = Filename1
Set NewSheet = ActiveSheet
Thank you in advance,
Best Regards,
BorisGomel
I am adding the new sheet to existing workbook and the file that is being imported name like this 07-13-11.xls and I would like to name the new sheet as 071311. The below is code that I am able come up so far and it return the name 07-13-11.xls. I am not gof to use InStr Function , please really apreciate for help:
Sub AddWorksheet()
Dim FileName2 As String
Dim Filename1 As String
Dim FileName3 As String
Dim FileName4 As String
Dim FileName5 As String
Dim Year As String
Dim Filename As String
Dim FLName As String
FLName = Application.GetOpenFilename
Dim NewSheet As Worksheet
Filename1 = Right(FLName, 12)
FileName2 = Mid(Filename1, InStr(Filename1, "-") + 8, 12)
FileName3 = Mid(Filename1, InStr(Filename1, "-") + 1, 2)
FileName4 = Mid(Filename1, InStr(Filename1, "-") + 3, 2)
Year = "2011"
FileName5 = FileName3 + "/" + FileName4 + "/" + Year
Worksheets.Add().Name = Filename1
Set NewSheet = ActiveSheet
Thank you in advance,
Best Regards,
BorisGomel