Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop drive driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network printer problem ram random registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Find and replace the date format in Word file

Reply  
Thread Tools
vinwin06's Avatar
Computer Specs
Member with 133 posts.
 
Join Date: Jul 2010
Experience: Intermediate
28-Jul-2010, 07:59 PM #1
Smile Solved: Find and replace the date format in Word file
Hi,

I want to find and replace the Date format in word, if there is any macro coding for this. I try to using the following codes

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " 7/"
.Replacement.Text = " 07/"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

But "7" is relates to month, so if there is any code for change the numeric character to specific date format as "mm".

For ex :

BUARDC 04294008295 010321 6000 7/17/2010 0000354652 000224

The above is the example data , in that month needs to added a leading zero.

Thanks in advance
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
29-Jul-2010, 11:20 AM #2
Would the "7/" you want to change always be preceded by a blank space and, if the day was the 7th, would it always be of the form "/7"?
If so, then all you need to do is search and replace " 7/" with " 07/" (excluding the parentheses, of course.)
vinwin06's Avatar
Computer Specs
Member with 133 posts.
 
Join Date: Jul 2010
Experience: Intermediate
29-Jul-2010, 09:46 PM #3
But if it's only for July "7", but what about other months came, so i just want to change that month format, i just want to do by way of "07". if there is any macro coding for changing for all the months.
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
30-Jul-2010, 01:37 AM #4
Oh, I am sure a decent coder could set a variable (say "i") in there, set "i"=1 and run it, then have a line where "i"="i"+1 and run it again until "i"=13. But that's beyond my skill set. I'll send a note to one of my buddies here and see if he can help you.
Edit - oh, you only have to run it through 9...10, 11 and 12 are already going to be 2 digits. Duh.
__________________
Iowa? I could have sworn this was heaven.
Well, I think I can answer this question most successfully in mime.
My theme song... | Affero - rate me!

Last edited by slurpee55; 30-Jul-2010 at 10:44 AM..
Keebellah's Avatar
Computer Specs
Senior Member with 3,541 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Never too old to learn!
30-Jul-2010, 04:02 AM #5
I'll take a shot at it.

Will the string all be identical like the one you sent? I refer to the date part

BUARDC 04294008295 010321 6000 7/17/2010 0000354652 000224
Keebellah's Avatar
Computer Specs
Senior Member with 3,541 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Never too old to learn!
30-Jul-2010, 04:25 AM #6
Why are you doing this in Word?
It looks like a logfile to me, is that correct?
It would be simpler to as a vbs script
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
30-Jul-2010, 11:21 AM #7
This works in Word, as near as I can tell.
Code:
Sub Replacetext()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
n = 1
For n = 1 To 9
With Selection.Find
.Text = " " & n & "/"
.Replacement.Text = " 0" & n & "/"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next n
End Sub
Keebellah's Avatar
Computer Specs
Senior Member with 3,541 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Never too old to learn!
30-Jul-2010, 11:58 AM #8
Slurpee, the code's perect,

I just added a second routine and the select all

Code:
Sub Replacetext()
Dim n As Integer
Selection.WholeStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
n = 1
For n = 1 To 9
With Selection.Find
.Text = " " & n & "/"
.Replacement.Text = " 0" & n & "/"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next n

For n = 1 To 9
With Selection.Find
.Text = "/" & n & "/"
.Replacement.Text = "/0" & n & "/"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next n
Selection.MoveDown Unit:=wdLine, Count:=1

End Sub
Just put this macro in the vba project and run it!!
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
30-Jul-2010, 12:04 PM #9
Thanks Hans - I never thought about the day possibly not being two digits, given the layout of the data supplied, but your code covers that possibility.
vinwin06's Avatar
Computer Specs
Member with 133 posts.
 
Join Date: Jul 2010
Experience: Intermediate
30-Jul-2010, 10:23 PM #10
Hi,

Thanks for your effort, but the problem is the spacing should not be changed in the file.

For ex:
BUARD2 04596009620 010327 14260 7/15/2010 0000354485 2799

In the above example there is a two space between the date and the next item, so the leading zero should be adjusted in the two spaces, so after adding the leading zero to the "month" (07) there should be one space between them.

After conversion the data should be like below ;

BUARD2 04596009620 010327 14260 07/15/2010 0000354485 2799

Kindly help me!!!
slurpee55's Avatar
Computer Specs
Distinguished Member with 7,837 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
31-Jul-2010, 01:59 AM #11
vin, the data you had posted earlier copied to Excel with only one space before the date, as do both of the examples you just posted. In your last post the first string is 57 characters long and the latter is 58 - because of the added 0. Otherwise they are identical. If you also use Han's code and change the day, then that will extend some possible dates by 2 added zeros.
If your data has an extra blank space (instead of a zero) preceding the date (and it just didn't copy over here well), change the code so that this line (from mine):
.Replacement.Text = " 0" & n & "/"
becomes:
.Replacement.Text = "0" & n & "/"
However, given what you posted, after conversion this would change your data into:
BUARD2 04596009620 010327 1426007/15/2010 0000354485 2799
__________________
Iowa? I could have sworn this was heaven.
Well, I think I can answer this question most successfully in mime.
My theme song... | Affero - rate me!
vinwin06's Avatar
Computer Specs
Member with 133 posts.
 
Join Date: Jul 2010
Experience: Intermediate
31-Jul-2010, 10:39 AM #12
Hi,

The leading zero should be adjusted after date and not before the date, the zero should be added to the space available after "2010" and before the number "0000354485".

Kindly help me for this.
Keebellah's Avatar
Computer Specs
Senior Member with 3,541 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Never too old to learn!
31-Jul-2010, 11:30 AM #13
Well, then edit code to do that.

You have an idea now

.Text = "/2010 "
.Replacement.Text = "/2010 "

You'll get an extra space after 2010, just look at the code and I think you'll be able to work it out.
vinwin06's Avatar
Computer Specs
Member with 133 posts.
 
Join Date: Jul 2010
Experience: Intermediate
31-Jul-2010, 11:40 AM #14
HI,

Already i have an extra space after "2010", this leading zero in month (07) should use the space after the 2010.
Keebellah's Avatar
Computer Specs
Senior Member with 3,541 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Never too old to learn!
31-Jul-2010, 11:58 AM #15
So this means thatyouwon't have any space after 2010 if the month is two-digit?

Do you two spaces if the day is one-digit?
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Solved: Macro Multiple Find and Replace in Excel 2007 Lynchie Business Applications 7 25-Sep-2009 07:06 AM
Solved: Excel - Find and replace using lists RandomMan Business Applications 1 17-Aug-2009 11:03 AM
Solved: Date format in bat file bikey33 DOS/Other 7 01-Jul-2009 12:48 AM
[Help] Find and Replace text evilracer All Other Software 1 14-Jan-2009 05:41 PM
Excel - Find and replace the right most comma MattMurphy Business Applications 2 10-Oct-2007 03:17 AM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:20 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.