Étape 5: Code Monkey !
1) copiez le code suivant fait en sorte à chaque fois que la personne qui utilise les types word E le document se ferme sans enregistrer les modifications. Le code est
Void AddKeyBinding()
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyE), CatégorieTouche: = wdKeyCategoryCommand, _
Commande: = « TestKeybinding »
End Sub
Void TestKeybinding()
Dim x As Document
Set x = ActiveDocument
x.Close (faux)
End Sub
2) cette farce rend mots souvent mal orthographiés apparaissent correctes donc aucune ligne rouge ne s’affiche en dessous.
Void AutoExec()
Appel WriteToATextFile
Dim dicCustom As Dictionary
Set dicCustom = Application.CustomDictionaries _
. Add(FileName:="c:\customdic5.dic")
Application.CustomDictionaries.ActiveCustomDictionary = dicCustom
Associé à l’Application
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeySpacebar), CatégorieTouche: = wdKeyCategoryCommand, _
Commande: = « spellit »
Se termine par
End Sub
Void WriteToATextFile()
MyFile = « c:\customdic5.dic »
FNUM = FreeFile()
Ouvert MyFile pour sortie comme fnum
Impression #fnum, « la »
Impression #fnum, « Té »
Fermer #fnum
End Sub
Public Sub spellit()
Selection.TypeText Text: = ""
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Avec Selection.Find
. Text = « the »
. Replacement.Text = « the »
. Forward = True
. Wrap = wdFindContinue
. Format = False
. MatchCase = True
. MatchWholeWord = False
. MatchWildcards = False
. MatchSoundsLike = False
. MatchAllWordForms = False
Se termine par
Remplacer Selection.Find.Execute: = wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Avec Selection.Find
. Text = « The »
. Replacement.Text = « Té »
. Forward = True
. Wrap = wdFindContinue
. Format = False
. MatchCase = True
. MatchWholeWord = False
. MatchWildcards = False
. MatchSoundsLike = False
. MatchAllWordForms = False
Se termine par
Remplacer Selection.Find.Execute: = wdReplaceAll
End Sub
3) cette farce rend jure au hasard apparaissent alors que la personne est saisissant.
Void typeRand()
Dim compteur As String
compteur = CStr (Int ((30-1 + 1) * Rnd + 1))
Application.OnTime quand: = Now + TimeValue ("00:00:" + compteur), _
Nom: = « TimedClose »
End Sub
Void TimedClose()
Dim maindocument As Document
Set maindocument = activedocument
compteur = CStr (Int ((5-1 + 1) * Rnd + 1))
Sélectionnez un compteur affaire
Cas 1
Selection.TypeText Text: = ""
Cas 2
Selection.TypeText Text: = ""
Cas 3
Selection.TypeText Text: = ""
Cas 4
Selection.TypeText Text: = ""
Cas no 5
Selection.TypeText Text: = ""
End Select
Appel typeRand
End Sub