Reading a string in the Filename

R

Ron_D

Hi All!
I'm new to writing codes in Outlook. I need a code that looks for a date
string within the filename of an email attachment. I've ask the people in
the field to name their attachment with a date format of "mm-dd-yyyy". And
the string can be anywhere within the filename. If the filename doesn't
contain a date information in the format I need, it exits the macro. If it
does, then it goes and saves the attachment to disk.

Thanks in advance,
Ron
 
M

Michael Bauer [MVP - Outlook]

If you can be sure, the people use the format you want to have then this
might work:

For i=1 to Len(text)
If IsDate(Mid$(text,i, Len("mm-dd-yyyy") Then
' match
Exit For
Endif
Next

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Fri, 15 Aug 2008 03:50:00 -0700 schrieb Ron_D:
 
R

Ron_D

Michael,
That did the trick!! Thank you for your help.

I've also added a 2nd condition in the If statement. Because I can't
guarrantee that the field will always name the file with the proper date
format, I've amended the if statement to look like this:

If IsDate(Mid$(text,i,Len("mm-dd-yyyy"))) AND
Len(trim(Mid$(text,i,Len("mm-dd-yyyy"))))=Len("mm-dd-yyyy") then

' Do Stuff

end if


-Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top