bonjour,
dans un répertoire, j'ai un fichier excel nommé SynSurestaries.xls qui contient une macro.
Dans le même répertoire, je copie un ficheir SynSurestaries.sur

quand j'ouvre le fichier excel, je lance ma macro.
Le code est le suivant :

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Private Sub Workbook_Open()
'
' OpusCout Macro
' Macro enregistrée le 11/12/2007 par EMMANUEL MOTTET
'
 
'On supprime toutes les cellules par défaut pour avoir un document vierge
    Cells.Select
    Selection.Delete Shift:=xlUp
 
'
  Dim chaine As Variant
  chaine = ActiveWorkbook.Path & "\SynSurestaries.sur"
 
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;chaine" _
        , Destination:=Range("A1"))
        .Name = "SynSurestaries"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Range("A1:H1").Select
    Selection.CurrentRegion.Select
    Selection.AutoFormat Format:=xlRangeAutoFormatClassic2, Number:=True, Font _
        :=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
    Range("A1:P1").Select
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = 6
    End With
    Range("A2:P26").Select
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = 12
    End With
    Range("A27:P27").Select
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = 6
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With Selection.Interior
        .ColorIndex = 54
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
    End With
End Sub
J'ai une erreur 1004 qui correspond au fait qu'il ne trouve pas le fichier.
si je remplace chaine par le path complet avec le nom du fichier (ex: L:\Projets\Projet OPUS\Projet OPUS 2006\DonneesOPUS 2007\2611lun14h\resultats\SynSurestaries.sur), cela fonctionne.

Comment faire pour que cela marche quel que soit le répertoire où se trouve le fichier xls et sur?

merci