Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    May 2009
    Posts
    16
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Bigbro's - Macros in Word 2003

    I'm new to macros, but have been successful at recording some easy ones. I have also played within the Visual Basic Editor and discovered how to do minor changes to a macro, even combining two or more macros together into one. They work fine, but I do not know how to create a macro and assign a button to it. I do not use keyboard shortcuts, because I'm not a typist and for that reason they don't save me much time.

    I would like to create a macro and a menu button to change the format of dates that I copy and paste into my documents, when I do my bank budgeting. I change the format to one that is more familiar to me. When I have a date that appears like this: 2/3/2013, I want it to be 02-03-12. Since those numbers will change every day the macro will need to convert any number ahead of the forward slashes to a double digit format and change the forward slashes to hyphens. I will then create a macro for next year and the following etc.

    Grateful for your answer,
    bigbro.51
    Last edited by bigbro51; 2013-01-09 at 18:28.

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Does this work as expected?
    Code:
    Sub ChangeTheDates()
    ' Replaces dates in #/#/0000 format with 00-00-00 format
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        
        .Text = "([0-9]{1,2})/([0-9]{1,2})/20([0-9]{2})"
        .Replacement.Text = "0\1-0\2-\3"
        .Execute Replace:=wdReplaceAll
        
        .Text = "0([1-3])([0-9])-"
        .Replacement.Text = "\1\2-"
        .Execute Replace:=wdReplaceAll
      End With
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    bigbro51 (2013-01-13)

  4. #3
    New Lounger
    Join Date
    May 2009
    Posts
    16
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I copied and pasted the macro you created and pasted it into th last position of the Visual Basic editor. I then searched for the macro in the Customize / Macros and drug it to the toolbar of a Word document. I typed 0/0/13 and press the button, but nothing happened. I found that it only worked if I copied and pasted as you had indicated with 0/0/2013. I need it more for the following format (0/0/13), however the one you sent is handy and I am thanful for it as well.

    Gratefilly,
    bigbro51
    Last edited by bigbro51; 2013-01-13 at 00:42.

  5. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    BigBro

    Your original post specified the date with the 2013 year so the code was written that way. If your dates show the year with only two digits then you can modify the first find text line to say

    .Text = "([0-9]{1,2})/([0-9]{1,2})/([0-9]{2})"
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #5
    New Lounger
    Join Date
    May 2009
    Posts
    16
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Wow - works great!

    Thank you very much Andrew!

    Gratefully,
    bigbro

Posting Permissions

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