In part of my code I need to store the name of the workbook into a cell. This part is easy. the challenge is that I need to delete the last part of the workbook name if it contains a date or time. Let me illustrate below:
When the user closes the file, the code automatically date and time stamps it and thens saves it. (Meaning the current date and time are inserted into the save name). Now the problem is that at a later point (if they open the file again) when the workbook name is copied into a cell, the cell automatically ands the date and time to the name, thus leaving me with a filename which has multiple dates and times.
if that explaination wasn't clear, let me know and i'll try again.
so what I need is a way to test the format of the last 11 characters of the file name. here's what I used, but it doesn't work. But it'll at least maybe show what I need to do:
This part inputs the date and time stamp upon file close.
Now here is where I tried to check the format:
I get an error at the bolded line, which is natural since I tried to use the .format different than how it was designed. But you cans ee what I'm trying to do, I just don't know which function to use.
When the user closes the file, the code automatically date and time stamps it and thens saves it. (Meaning the current date and time are inserted into the save name). Now the problem is that at a later point (if they open the file again) when the workbook name is copied into a cell, the cell automatically ands the date and time to the name, thus leaving me with a filename which has multiple dates and times.
if that explaination wasn't clear, let me know and i'll try again.
so what I need is a way to test the format of the last 11 characters of the file name. here's what I used, but it doesn't work. But it'll at least maybe show what I need to do:
This part inputs the date and time stamp upon file close.
Code:
ErrorHandler:
Do
CurDate = Format(Date, "dd-mmm-yy")
CurTime = Format(Time, "hh-mm-ss AMPM")
fName = Application.GetSaveAsFilename("CDM RA Request" & "__" & CurDate & "_" & CurTime, "Microsoft Excel Worksheet (*.xls), *.xls")
Loop Until fName <> False
On Error GoTo ErrorHandler
ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlNormal
Now here is where I tried to check the format:
Code:
CurName = ActiveWorkbook.Name
[b]If Right(CurName, 11).Format = "hh-mm-ss AMPM" Then[/b]
LengthVar = Len(CurName) - 23
CurName = Left(CurName, LengthVar)
End If
I get an error at the bolded line, which is natural since I tried to use the .format different than how it was designed. But you cans ee what I'm trying to do, I just don't know which function to use.