Voorbeeldmacro's in Word
-
Macro 1 spoort 'meerdere spaties : spatie' op en vervangt door ^t:^t
(^t = tabulatie)' Opmaak macro
Selection.HomeKey Unit:=wdStory
' 17 spaties zonder dubbelpunt
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = "^t^t"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 15 spaties
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " : "
.Replacement.Text = "^t:^t"
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 14 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 13 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 12 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 11 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 10 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 9 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 8 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 7 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 6 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 5 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 4 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 3 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
' 2 spaties
Selection.Find.ClearFormatting
With Selection.Find
.Text = " : "
End With
Selection.Find.Execute Replace:=wdReplaceAll
-
Macro 2 zoekt een woord in het word document. Enkel indien dit woord gevonden is wordt de macro uitgevoerd en de term wordt verwijderd. Zo wordt de marco eenmalig uitgevoerd.
' Deze macro zoekt de tekst CERM_LAYOUT in het document
' Indien gevonden wordt de tekst weggelaten en de rest van de macro wordt uitgevoerd
' zoniet gebeurt er niets
Set Inhoud = ActiveDocument.Content
With Inhoud.Find
.MatchCase = True
.Wrap = wdFindContinue
.Replacement.Text = ""
.Execute FindText:="CERM_LAYOUT", Forward:=True
End With
If Inhoud.Find.Found = True Then
Inhoud.Find.Execute Replace:=wdReplaceAll
MsgBox "Gevonden."
Else
MsgBox "Niet gevonden."
End If
-
Macro 3 zoekt de munt Eur en vervangt deze door het Euro teken €
Vervolgens wordt het document doorlopen en alles vanaf € tot het eind van de lijn wordt vet gedrukt.' Ga naar Home
Selection.HomeKey Unit:=wdStory
' Vervang Eur door €
With ActiveDocument.Content.Find
.ClearFormatting
.Text = "Eur"
With .Replacement
.ClearFormatting
.Text = "€"
End With
.Execute Replace:=wdReplaceAll, _
Format:=True, MatchCase:=True, _
MatchWholeWord:=True
End With
' Ga naar Home
Selection.HomeKey Unit:=wdStory
' max. 100 vervangingen ?
For i = 1 To 100
' Selecteer t.e.m. €
With Selection
.MoveEndUntil Cset:="€", Count:=wdForward
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
' Verlaat de selectie
Selection.EscapeKey
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' Selecteer enkel de eerstvolgende positie
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Text = "€" Then
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Bold = True
Selection.MoveRight Unit:=wdCharacter, Count:=1
End If
Next i
CermHelp v7.11 (R2) |