gerardcjf
Messages postés47Date d'inscriptionmardi 3 juillet 2007StatutMembreDernière intervention26 décembre 2013
-
6 juin 2011 à 09:57
gerardcjf
Messages postés47Date d'inscriptionmardi 3 juillet 2007StatutMembreDernière intervention26 décembre 2013
-
6 juin 2011 à 11:55
Bonjour,
Je souhaite récupérer, via une macro, un élément contenu dans l'entête d'un document word.
Avec l'enregistreur de macro j'ai la macro suivante :
Sub Recupération_IR()
msg = "S'agit il d'une LO ?"
reponse = MsgBox(msg, vbYesNo)
If reponse = vbNo Then
Selection.WholeStory
With Selection.Font
.Name = "Arial"
.Size = 9
End With
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
End If
If reponse = vbYes Then
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Siren :"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend
Selection.Copy
Selection.Find.ClearFormatting
With Selection.Find
.Text = "toto"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.PasteAndFormat (wdPasteDefault)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
ActiveWindow.Panes(2).Activate
Selection.Find.ClearFormatting
With Selection.Find
.Text = "N° de personne :"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=8, Extend:=wdExtend
Selection.Copy
ActiveWindow.ActivePane.Close
Selection.Find.ClearFormatting
With Selection.Find
.Text = "tata"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.PasteAndFormat (wdPasteDefault)
Selection.WholeStory
With Selection.Font
.Name = "Arial"
.Size = 9
End With
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
End If
End Sub
Quand je change de document et que je lance la macro elle s'arrête à ce niveau :
ActiveWindow.Panes(2).Activate
Je précise que la macro s'executera toujours sur des documents qui sont formalisés de manière identiques.
Je ne vois pas le problème ... Pouvez vous m'aider ?