Can date format be changed

  • Thread starter Francis Hookham
  • Start date
F

Francis Hookham

I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight forward to
change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d mmmm yy (Tue, 5
September 06) if I wished.

Many thanks,

Francis Hookham
 
D

Doug Robbins - Word MVP

The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the Format
function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

Francis Hookham

Fantastic - just right - I must try to understand the composition of do
loops, my upbringing has been self-help from the difficult early days of XL
macros and While/Wend is as far as I have got - anywhere in particular for
me to look on the net for do loops in depth?

Thank you very much

Francis Hookham

Doug Robbins - Word MVP said:
The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the
Format function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight forward
to change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d mmmm yy
(Tue, 5 September 06) if I wished.

Many thanks,

Francis Hookham
 
D

Doug Robbins - Word MVP

Just the visual basic help file. That's my only reference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
Fantastic - just right - I must try to understand the composition of do
loops, my upbringing has been self-help from the difficult early days of
XL macros and While/Wend is as far as I have got - anywhere in particular
for me to look on the net for do loops in depth?

Thank you very much

Francis Hookham

Doug Robbins - Word MVP said:
The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the
Format function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight forward
to change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d mmmm yy
(Tue, 5 September 06) if I wished.

Many thanks,

Francis Hookham
 
F

Francis Hookham

Thanks - I must load VB Help onto this elderly desktop - normally I use the
new laptop which has everything on it but it's dead at present and I'm
limping! Fortunately it is under warranty.

One last request - just before your Do Loop runs to change all the dates
from dd.MM.yy to ddd, d MMM yy I should like to Copy the first date, which
comes at the beginning of the second paragraph, and Paste it into the first
paragraph in the format MMMM yy.

The first paragraph has nothing in it but I shall add in bold "Rotary Club
of Cambridge - Calendar from " followed by the MMMM yy

I am most grateful

Francis Hookham


Doug Robbins - Word MVP said:
Just the visual basic help file. That's my only reference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
Fantastic - just right - I must try to understand the composition of do
loops, my upbringing has been self-help from the difficult early days of
XL macros and While/Wend is as far as I have got - anywhere in particular
for me to look on the net for do loops in depth?

Thank you very much

Francis Hookham

Doug Robbins - Word MVP said:
The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the
Format function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight forward
to change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d mmmm yy
(Tue, 5 September 06) if I wished.

Many thanks,

Francis Hookham
 
F

Francis Hookham

One last request - just before your Do Loop runs to change all the dates
from dd.MM.yy to ddd, d MMM yy I should like to Copy the first date, which
comes at the beginning of the second paragraph, and Paste it into the first
paragraph in the format MMMM yy.

The first paragraph has nothing in it but I shall add in bold "Rotary Club
of Cambridge - Calendar from " followed by the MMMM yy

I am most grateful

Francis Hookham

Doug Robbins - Word MVP said:
Just the visual basic help file. That's my only reference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
Fantastic - just right - I must try to understand the composition of do
loops, my upbringing has been self-help from the difficult early days of
XL macros and While/Wend is as far as I have got - anywhere in
particular for me to look on the net for do loops in depth?

Thank you very much

Francis Hookham

The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the
Format function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight
forward to change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d
mmmm yy (Tue, 5 September 06) if I wished.

Many thanks,

Francis Hookham
 
D

Doug Robbins - Word MVP

Insert the following before the previous code:

Dim drange As Range
With ActiveDocument
Set drange = .Paragraphs(2).Range
drange.End = drange.Start + 10
.Range.InsertBefore "Rotary Club of Cambridge - Calendar from " &
Format(Mid(drange, 4, 2) & "/" _
& Left(drange, 2) & "/" & Right(drange, 4), "MMMM yy")
.Paragraphs(1).Range.Font.Bold = True
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
One last request - just before your Do Loop runs to change all the dates
from dd.MM.yy to ddd, d MMM yy I should like to Copy the first date, which
comes at the beginning of the second paragraph, and Paste it into the
first paragraph in the format MMMM yy.

The first paragraph has nothing in it but I shall add in bold "Rotary Club
of Cambridge - Calendar from " followed by the MMMM yy

I am most grateful

Francis Hookham

Doug Robbins - Word MVP said:
Just the visual basic help file. That's my only reference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Fantastic - just right - I must try to understand the composition of do
loops, my upbringing has been self-help from the difficult early days
of XL macros and While/Wend is as far as I have got - anywhere in
particular for me to look on the net for do loops in depth?

Thank you very much

Francis Hookham

The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the
Format function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight
forward to change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d
mmmm yy (Tue, 5 September 06) if I wished.

Many thanks,

Francis Hookham
 
F

Francis Hookham

Thank you - just right after swapping round (as previously) to
Left/Mid/Right for UK format of d MMM yy

Francis Hookham


Doug Robbins - Word MVP said:
Insert the following before the previous code:

Dim drange As Range
With ActiveDocument
Set drange = .Paragraphs(2).Range
drange.End = drange.Start + 10
.Range.InsertBefore "Rotary Club of Cambridge - Calendar from " &
Format(Mid(drange, 4, 2) & "/" _
& Left(drange, 2) & "/" & Right(drange, 4), "MMMM yy")
.Paragraphs(1).Range.Font.Bold = True
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Francis Hookham said:
One last request - just before your Do Loop runs to change all the dates
from dd.MM.yy to ddd, d MMM yy I should like to Copy the first date,
which comes at the beginning of the second paragraph, and Paste it into
the first paragraph in the format MMMM yy.

The first paragraph has nothing in it but I shall add in bold "Rotary
Club of Cambridge - Calendar from " followed by the MMMM yy

I am most grateful

Francis Hookham

Just the visual basic help file. That's my only reference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Fantastic - just right - I must try to understand the composition of
do loops, my upbringing has been self-help from the difficult early
days of XL macros and While/Wend is as far as I have got - anywhere in
particular for me to look on the net for do loops in depth?

Thank you very much

Francis Hookham

The following should do it

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{2}.[0-9]{2}.[0-9]{4}",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Text = Format(Mid(Selection.Text, 4, 2) & "/" &
Left(Selection.Text, 2) & "/" & Right(Selection.Text, 4), "d MMM yy")
Loop
End With

You can get different formats by simply modifying the d MMM yy in the
Format function.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I have a number of paragraphs which start with the date in the format
05.09.2006
that is dd.mm.yyyy

Please can you write a macro to find dates in dd.mm.yyyy format
and change them to d mmm yy format, that is 5 Sep 06

Having seen how to do that, I take it that it would be straight
forward to change instead to ddd, d mmm yy (Tue, 5 Sep 06) or ddd, d
mmmm yy (Tue, 5 September 06) if I wished.

Many thanks,

Francis Hookham
 

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

Similar Threads

Date format. 2
Date Format - simple question 1
Dates Challenge 0
Date in footer 3
Pasting a date to a cell from UserForm 2
Week starts on Friday 3
date and time difference 19
VBA in Excel 2007 date formatting 2

Top