Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check the format of a string?

Status
Not open for further replies.

bdmangum

Technical User
Dec 6, 2006
171
US
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.
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.
 
You have an error as there is no 'Format' property for string variable. try 'Like' operator to compare your string with pattern.

combo
 
thread68-890890 Shows how to do something similar with Regular Expressions.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top