Copier un élément de l'en-tête dans word 2007

Résolu
gerardcjf Messages postés 47 Date d'inscription mardi 3 juillet 2007 Statut Membre Dernière intervention 26 décembre 2013 - 6 juin 2011 à 09:57
gerardcjf Messages postés 47 Date d'inscription mardi 3 juillet 2007 Statut Membre Dernière intervention 26 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 ?

Davance merci ....

1 réponse

gerardcjf Messages postés 47 Date d'inscription mardi 3 juillet 2007 Statut Membre Dernière intervention 26 décembre 2013
6 juin 2011 à 11:55
Ne cherchez plus j'ai trouvé ... en fait il faut passer par le menu affichage de word puis par modifier l'en tete ce qui donne en code :

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Find.ClearFormatting
With Selection.Find
.Text = "personne :"
.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:=1
Selection.MoveRight Unit:=wdCharacter, Count:=9, Extend:=wdExtend
Selection.Copy
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
...

En espérant que cela serve.
3
Rejoignez-nous