Problème rayage de texte VBA

Fermé
Boosterz Messages postés 59 Date d'inscription mardi 13 juin 2017 Statut Membre Dernière intervention 28 juin 2017 - 20 juin 2017 à 08:53
Argitxu Messages postés 4831 Date d'inscription dimanche 22 juillet 2007 Statut Contributeur Dernière intervention 3 mars 2024 - 20 juin 2017 à 16:04
Bonjour,

Je cherche comment faire pour résoudre un soucis sur Word en VBA :
- J'ai une page Y de mon document qui est répété X fois suivant la valeur d'une comboBox ( 1 à 4 )
- Sur ses différentes pages il y a des noms de ville et suivant quelle est la ville sélectionné et le numéro de site qui est adapté à la page je voudrais que les autres soit rayé voici le code que j'ai fais mais qui ne fonctionne pas.

    Dim LigneD As Integer
    Dim LigneF As Integer
    Set doc = ActiveDocument
    Set myRange = ActiveDocument.Range(Start:=LigneD, End:=LigneF)
        
    If (ComboBox1.Value = "1") Then
        LigneD = 4000
    ElseIf (ComboBox1.Value = "2") Then
        LigneD = 6000
    ElseIf (ComboBox1.Value = "3") Then
        LigneD = 9000
    ElseIf (ComboBox1.Value = "4") Then
        LigneD = 12000
    End If
    LigneF = LigneD + 1000
    

    
    If (ComboBoxNDs.Value = "VILLE4") Then
        Set doc = ActiveDocument
        Set myRange = ActiveDocument.Range(Start:=LigneD, End:=LigneF)
        
        myRange.find.Execute FindText:="VILLE1", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE2", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE3", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
    ElseIf (ComboBoxNDs.Text = "VILLE2") Then
        myRange.find.Execute FindText:="VILLE4", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE1", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE3", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
    ElseIf (ComboBoxNDs.Text = "VILLE1") Then
        myRange.find.Execute FindText:="VILLE4", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE2", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE3", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
    ElseIf (ComboBoxNDs.Text = "VILLE3") Then
        myRange.find.Execute FindText:="VILLE4", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE2", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
        myRange.find.Execute FindText:="VILLE1", Forward:=True
        If myRange.find.Found = True Then
            myRange.Font.StrikeThrough = True
        End If
    End If


Je sais que je me suis fais chier il y avait plus simple mais je ne voulais pas me prendre la tête... Enfin si quelqu'un à une solution je prend.

Merci

1 réponse

Argitxu Messages postés 4831 Date d'inscription dimanche 22 juillet 2007 Statut Contributeur Dernière intervention 3 mars 2024 4 739
20 juin 2017 à 16:04
Bonjour

Je ne pourrai te répondre car je suis nulle en macro.
Mais si tu veux une solution, pose ta question ici sur la faqword
http://faqword.com/forums/
Il y a des macroteurs word ;-))
1