Bonjour,
j'essaie de faire fonctionner un somme.si avec la fonction ExecuteExcel4Macro mais j'ai une erreur "La methode ... de l'objet global à echoué", est -il possible qu'il ne puisse récupérer que des valeurs et non faire un calcul (somme, somme.si ... etc) ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 MyFormula = ThisWorkbook.Worksheets("Feuil1").Range("A3").Formula MyLink = "O:\tatata" Mywb = "ST - TradingBook.xlsm" MySheet = "Trading08_09l" ThisWorkbook.Worksheets("Feuil1").Range("A4").Formula = ExtractCellRefs(MyFormula, MyLink, Mywb, MySheet) MyFormula = Right(ThisWorkbook.Worksheets("Feuil1").Range("A4").FormulaR1C1, Len(ThisWorkbook.Worksheets("Feuil1").Range("A4").FormulaR1C1) - 1) ThisWorkbook.Worksheets("Feuil1").Range("A4").Formula = MyFormula MyFormula = Replace(MyFormula, "'", "''") MyRes = ExecuteExcel4Macro(MyFormula)
Cordialement,
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 'Remplage une plage par son lien absolu Function ExtractCellRefs(ByVal MyFormula As String, ByVal MyBaseLink As String, ByVal Mywb As String, ByVal MySheet As String) As String Dim i As Byte, Results As Object Dim MyLink As String, regexpattern As String 'Pattern regexpattern = "('?[a-zA-Z0-9\s\[\]\.]{1,99})?'?!?\$?[A-Z]{1,3}\$?[0-9]{1,7}(:\$?[A-Z]{1,3}\$?[0-9]{1,7})?" 'MyLink Mywb = Replace(Mywb, "'", "''") MySheet = Replace(MySheet, "'", "''") MyLink = "'" & MyLink & "[" & Mywb & "]" & MySheet & "'!" With CreateObject("vbscript.regexp") .Global = True: .MultiLine = True: .IgnoreCase = False: .Pattern = regexpattern Set Results = .Execute(MyFormula) If Results.Count <> 0 Then For i = 0 To Results.Count - 1 MyFormula = Replace(MyFormula, Results.Item(i).Value, MyLink & Results.Item(i).Value) Next i End If End With ExtractCellRefs = MyFormula End Function
Partager