1.La suite VBA , ici-bas, à l'aire bonne mais elle ne marche pas et je n'arrive pas non plus à trouver où est l'erreur.

2. Il faut savoir que si j'ouvre "à la main", et avant de lancer la macro, la connexion internet sur la Feuille Excel active (Onglet Données > A partir de Web > etc. , alors, dans ce contexte precis, la macro marche !!!! : un truc d'ouf !!!
3. En lisant en détail l'aide sur la fiche "QueryTables.Add, méthode" que l'on peut éditer grâce à l'Aide Excel, je me suis aperçu qu'il y a plusieurs manières de construire la "connexion" avec la source de données et une source URL (comme celle qui est sur la suite) est tout à fait possible...donc où est le dysfonctionnement de mon code ?

Merci à l'avance d'un regard nouveau....

Voici le code complet :
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
 Option Explicit
Sub ImporterCommandesPasLots()
 
Dim MyPost As String
Const MyUrl As String = "http://www.---------index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id="
Const MyName As String = "Commande_id="
Const PostUser As String = "username=daniel" 'Change user name here
Const PostPassword As String = "&passwd=@@@@@@@@@" 'Change password here
 
Dim CompteurID%
 
Dim Depart$, Final$, Hoja$
 
Depart = InputBox("Saisir ID Point de Départ", , "118")
Final = InputBox("Saisir Dernier ID Commande", , "119")
 
 
 
If Depart = "" Or Final = "" Then
Exit Sub
End If
 
 
 
For CompteurID = CInt(Depart) To CInt(Final)
 
 
        If ActiveSheet.Range("A1").Value <> "" Then
 
                Sheets.Add After:=Sheets(Sheets.Count)
 
                Sheets(Sheets.Count).Name = "Feuil_" & CInt(Mid((Sheets(Sheets.Count - 1).Name), 7, Len(Sheets(Sheets.Count - 1).Name) - 10)) + 1 & "_" & CStr(CompteurID)
 
                Hoja = Sheets(Sheets.Count).Name
 
                Sheets(Sheets.Count).Range("A1").Select
 
        ElseIf ActiveSheet.Range("A1").Value = "" Then
 
                ActiveSheet.Name = "Feuil_" & CInt(Mid((Sheets(Sheets.Count - 1).Name), 7, Len(Sheets(Sheets.Count - 1).Name) - 10)) + 1 & "_" & CStr(CompteurID)
 
                Hoja = ActiveSheet.Name
 
                ActiveSheet.Range("A1").Select
 
        End If
 
With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;" & MyUrl & CStr(CompteurID), _
        Destination:=Sheets(Hoja).Range("$A$1"))
        .Name = MyName & CStr(CompteurID)
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "1,5,9,10"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
End With
 
'DoEvents
 
    If CInt(Depart) = CInt(Final) Then
 
        ActiveWorkbook.Connections(1).Delete
 
    ElseIf CompteurID <> CInt(Depart) And _
        CompteurID < CInt(Final) Then
 
        ActiveWorkbook.Connections(2).Delete
        Sheets.Add After:=Sheets(Sheets.Count)
 
    ElseIf CompteurID = CInt(Final) Then
        ActiveWorkbook.Connections(2).Delete
        ActiveWorkbook.Connections(1).Delete
 
    End If
 
 
Next CompteurID
 
 
 
End Sub