2016-03-21 18 views
1

BenÇalışma - makro 4'ten tarih

Yani lider tarihleri ​​sıfır (özellikle tarih ve ay) eklemek için VBA kullanarak Microsoft Word 2013'te bir makro yapmaya çalışıyorum giden sıfırları eklemek/6/2004 5/11/2005

05/11/2005 için 04/06/2004 Ve burada cevabın bir varyasyonunu kullanmaya çalıştı ama sonsuz ilk buluşmada döngüler: http://answers.microsoft.com/en-us/office/forum/office_2010-word/macro-to-convert-date-format-in-a-document/20539af7-a961-499f-9e85-22af8f4c3c58?auth=1

Sub ConvertDateFormat() 
Dim FoundOne As Boolean 
Selection.HomeKey Unit:=wdStory,   Extend:=wdMove 
FoundOne = True ' loop at least once 
Do While FoundOne ' loop until no  date is found 
    With Selection.Find 
     .ClearFormatting 
     .Replacement.ClearFormatting 
     .Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})" 
     .Format = True 
     .Forward = True 
     .MatchWildcards = True 
    End With 
    Selection.Find.Execute  Replace:=wdReplaceNone 
    ' check that the find is a date 
If IsDate(Selection.Text) Then 
     Selection.Text =  Format(Selection.Text, "dd/mm/yyyy") 
     Selection.Collapse  wdCollapseEnd 
    Else ' not a date - end loop 
     FoundOne = False 
    End If 
Loop 
End Sub 

cevap

0

Bunu deneyin ve neyin değiştiğimi öğrenin.

MS-kelimenin sanat bulup Range, çökmeye değiştirmemek için ve döngüler (ve süre yapmak) Win-7pro, 64, ofis 2010 Çalışma güzel

, 32

Sub ConvertDateFormat() 
With ActiveDocument.Range 
    With .Find 
     .ClearFormatting 
     .Replacement.ClearFormatting 
     .Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})" 
     .Format = True 
     .Wrap = wdFindStop 
     .Forward = True 
     .MatchWildcards = True 
     .Execute 
    End With 
    Do While .Find.Found 

    If IsDate(.Text) Then 
     .Text = Format(.Text, "dd/mm/yyyy") 
    End If 
    .Collapse wdCollapseEnd 
    .Find.Execute 
    Loop 
    End With 
End Sub 
+0

Merhaba Rahul, Değişiklikleri İzle kapalıysa makro çalışır. İlk arama sonucunun döngüsünü almadan rota değişiklikleri içeren bir çözüm istiyorsam - bununla nasıl giderim? –