Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Text or Number? (Word 2003)

    I am working on a project to get my users to save with a consistent naming format stating with yymmdd (060306). I am planning to do this by distributing a macro FileSaveAs. This will automatically set the first part of the name as 060306 then whatever filename they already have. However, if the first part of the filename is already in the proper date format, I don't want to precede it with another such as "060306 060301 My Letter". I want to determine if the first 6 character are numbers and if so, strip that out.

    In Word, can I evaluate for text v. numbers? Do I just need > 0 and < 13?

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Text or Number? (Word 2003)

    You could test like this:

    If IsNumeric(Left(ActiveDocument.Name, 6)) Then
    ...
    Else
    ...
    End If

    This doesn't guarantee that the first 6 characters form a valid date. If you want to do that, you could use:

    Dim strName As String
    strName = ActiveDocument.Name
    If Len(strName) < 6 Then
    ' Fewer than 6 characters - certainly no date
    ElseIf IsDate(Left(strName, 2) & "/" & Mid(strName, 3, 2) & "/" & Mid(strName, 5, 2)) Then
    ' Yep, it's a date
    Else
    ' Not a date
    End If

  4. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text or Number? (Word 2003)

    Because I am talking about the filename, I can't check for a date such as the format you suggest. The format we are trying to enforce is YYMMDD. So I am checking isnumeric on the first 2 digits, >0 AND < 13 on the second 2, and >0 AND < 32 on the last two. The still leaves some room for error, but will do what I want.

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Text or Number? (Word 2003)

    For yymmdd, the following should do:

    ElseIf IsDate(Mid(strName, 5, 2) & "/" & Mid(strName, 3, 2) & "/" & Left(strName, 2)) Then

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •