![]() |
|
Forum
|
|
|
#1 (permalink) |
|
Guest
Messages: n/a
|
Bonjour à tous voici un bout de code d'une macro excel qui à pour but d'ouvrir un doc word existant de rechercher la chaine "Insert_communes" et de la remplacer par "ville". Je n'arrive pas à aboutir à ce résultat sachant que j'ai constamment le message d'erreur "la méthode replacement de l'objet find à échoué" .
Peut - on m'aider Merci d'avance ! Sub word_transfert2() ' en projet Dim wordApp As word.Application Dim wordDoc As word.Document Dim vnomDoc As String Dim dossier_destination As String Dim dossier_source As String 'variable pour la création automatique des noms pour les rapports Dim dos As String Dim fchb As String Dim ns As String Dim det As Boolean Dim ext As String Dim i As Integer Set fs = CreateObject("Scripting.FileSystemObject") i = 0 dos = "C:\Macro_Edition\" fchb = "Rapport" det = True ext = ".doc" Do While det = True i = i + 1 ns = Str(i) vnomDoc = fchb & ns final = dos & vnomDoc & ext det = fs.FileExists(final) Loop dossier_source = "C:\Macro_Edition\" dossier_destination = "C:\Macro_Edition\" Set wordApp = CreateObject("Word.Application") wordApp.Visible = True Set wordDoc = wordApp.Documents.Open(dossier_source & "fiche2.doc") wordDoc.ActiveWindow.Selection.Find.ClearFormattin g ' ici c'est la partie qui m'intéresse là où se situe l'erreur With wordDoc.ActiveWindow.Selection.Find .Text = "Insert_communes" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With wordDoc.ActiveWindow.Selection.Find.Execute wordDoc.ActiveWindow.Selection.Delete Unit:=wdCharacter, Count:=1 wordDoc.ActiveWindow.Selection.TypeText Text:="ville" |
|
|
#2 (permalink) |
|
Guest
Messages: n/a
|
bonsoir Knecmotet
ci joint un exemple de macro pour remplacer un mot dans un document Word ( adapté de l'aide en ligne VBA ) Sub RemplacerMotDocWord() ' en projet 'necessite d'activer la reference microsoft Word xx.x Object Library Dim wordApp As Word.Application Dim wordDoc As Word.Document Set wordApp = CreateObject("Word.Application") wordApp.Visible = True Set wordDoc = wordApp.Documents.Open("C:\Documents and Settings\michel\test.doc") With wordDoc.Content.Find .ClearFormatting .Text = "Insert_communes" With .Replacement .ClearFormatting .Text = "ville" End With .Execute Replace:=wdReplaceAll .Forward = True .Wrap = wdFindContinue End With End Sub j'espere que cela pourra t'aider bonne soiree MichelXld |
| ANNONCES | |
| Liens sociaux |
| Outils de la discussion | |
|
|