Voilà où j'en suis : j'ai utilisé le pas à pas et le Debug.Print qui montrent que les valeurs sont bien transmises à la méthode find qui ne les trouvent pas...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 Option Explicit Dim folder As Variant 'Folder containing all the Workbooks Dim Continue As Integer Dim filename As String 'filename contains folder name and file extension concatenated into one string Dim OpenF As Boolean Dim destinationWorkbook As Workbook 'destinationWorkbook will change at each iteration of while Dim x As Integer, y As Integer 'Dim ToReplace As String, By As String Dim ToReplace(1 To 8) As String 'bad parts of links Dim By(1 To 8) As String 'to replace by the parts contained in this string Public Sub Update_HYPERLINKS_InAllWorkbooksInFolder() Application.DisplayAlerts = False 'Disables popup warnings Dim OpenAnother As Integer OpenAnother = 7 '7 is the integer value of vbNo (No button of MsgBox) Dim Tableau As Variant: Tableau = ThisWorkbook.Worksheets(1).Range("A2:B15").Value Dim k As Integer, l As Integer k = 1 For k = 1 To 8 ToReplace(k) = Tableau(k, 1) Debug.Print ToReplace(k) Next k l = 1 For l = 1 To 8 By(l) = Tableau(l, 2) Debug.Print By(l) Next l OpenF = False 'Do OpenF = OpenFilesInFolder While OpenF = True And Len(filename) <> 0 Set destinationWorkbook = Workbooks.Open(folder & filename) UnprotectFiles 'ReplaceStrings MultipleSearch ProtectFiles destinationWorkbook.Close True filename = Dir() ' Get next matching file Wend 'OpenAnother = MsgBox("Do you want to update another folder?" & Chr(10) & Chr(10) & "Yes to Open a new folder - No to Quit the application", _ 'vbQuestion + vbYesNo, "Updating another folder") 'Loop While OpenAnother = 6 '6 is the integer value of vbYes (Yes button of MsgBox): here the code will be repeated if OpenAnother = 6 (yes) End Sub Sub MultipleSearch() Application.FindFormat.Clear Dim SearchInRange As Range x = 1 For x = 1 To Worksheets.Count Set SearchInRange = destinationWorkbook.Worksheets(x).Range("A1:Z300") Dim cell As Range y = 1 For y = 1 To 8 Debug.Print ToReplace(y) Set cell = SearchInRange.Find(ToReplace(y), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False) ' If not found then exit If cell Is Nothing Then Debug.Print "Not found" Else ' Store first cell address Dim firstCellAddress As String firstCellAddress = cell.Address ' Find all cells containing Elli Do Debug.Print "Found: " & cell.Address Set cell = SearchInRange.FindNext(cell) cell.FormulaLocal = Replace(expression:=cell.FormulaLocal, Find:="$T$10:$U$500;2;", Replace:="$M$2:$U$500;3;", compare:=vbTextCompare) Loop While firstCellAddress <> cell.Address End If Next y Next x End Sub
Partager