Bonjour,

J'aimerais créer un fichier HTML reprenant certaines valeurs de mes feuilles avec mise en page et l'envoyer sur le Web via FTP...

J'ai trouvé des morceaux de codes, mais je n'y arrive pas...

Pour créer un fichier HTML
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
' --- Dans un module standard: ---
 
Option Explicit
 
Public Collect As Collection
Public MaVariable As String
 
 
Sub Test()
    Dim xFile As Integer
    Dim Cl As Classe1
    Dim LaPage As Object
 
    xFile = FreeFile
 
    Open "C:\CreationPage.html" For Output As xFile
        Print #xFile, "<HTML>"
        Print #xFile, "<HEAD>"
        Print #xFile, "<TITLE>Ma page de saisie</TITLE>"
        Print #xFile, "</HEAD>"
 
        Print #xFile, "<FORM>" & _
            "<input type='text' size='10' name='autre'><br>" & _
            "<INPUT type=button name='Bouton1' value='Validez'>" & _
            "</FORM>" & _
            "</BODY></HTML>"
        Print #xFile, "</BODY>"
        Print #xFile, "</HTML>"
    Close xFile
 
 
    Set Collect = New Collection
    Set LaPage = CreateObject("InternetExplorer.Application")
 
    Set Cl = New Classe1
    Set Cl.IE = LaPage
    Collect.Add Cl
 
    With LaPage
        .AddressBar = False
        .MenuBar = False
        .StatusBar = False
        .Toolbar = False
        .Visible = True
        .Width = 400
        .Height = 300
        .navigate "C:\CreationPage.html"
 
        Do Until .readyState = 4
            DoEvents
        Loop 'attend la fin du chargement
    End With
 
End Sub
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
' --- Dans un module de classe nommé Classe1 ---
 
Option Explicit
 
Public WithEvents IE As InternetExplorer
Dim WithEvents Bouton As HTMLInputElement
Dim MaPageHtml As HTMLDocument
 
 
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Set MaPageHtml = IE.document
 
    'pour cet exemple le bouton est le 2eme objet "input" de la page... Item(1)
    Set Bouton = MaPageHtml.getElementsByTagName("input").Item(1)
End Sub
 
 
Private Function Bouton_onclick() As Boolean
    'Récupère le contenu de la zone de saisie dans la page html
    MaVariable = MaPageHtml.getElementsByTagName("input").Item(0).Value
 
    MsgBox MaVariable
    IE.Quit
End Function
Pour l'envoyer sur le Web
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
Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias _
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, _
ByVal lpszDirectory As String) As Boolean
Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" ( _
ByVal hFtpSession As Long, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
 
 
Sub ftp()
'transfère des fichiers du disque local vers un serveur ftp (upload, mode passif)
Dim Start As Single
 
'PARAMETRES************************
fichier = "D:\chemin de ton fichier à transferer"
login = "login de ton ftp"
mot_passe = "mot de passe"
rép = "/www/dossier ou transferer le fichier sur ftp"
bin_asc = &H2 '(&H1 ascii, &H2 binaire)
Mode = &H8000000 '(&H8000000 mode passif, 0 mode actif)
'**********************************
 
'lancer le transfert
internet_ok = InternetOpen("PutFtpFile", 1, "", "", 0)
If internet_ok = 0 Then
MsgBox "connection internet impossible"
Exit Sub
End If
ftp_ok = InternetConnect(internet_ok, "ftp.nom de ton ftp.fr", 21, login, mot_passe, 1, Mode, 0)
If ftp_ok = 0 Then
MsgBox "connection impossible"
Exit Sub
End If
sélect_rép = FtpSetCurrentDirectory(ftp_ok, rép)
If sélect_rép = 0 Then
MsgBox "impossible de trouver le répertoire "
Exit Sub
End If
 
'nom du fichier sans le chemin
nomfich = fichier
Do While InStr(nomfich, "\") > 0
nomfich = Right(nomfich, Len(nomfich) - InStr(nomfich, "\"))
Loop
 
'transférer le fichier
succès = FtpPutFile(ftp_ok, fichier, nomfich, bin_asc, 0)
If succès Then
résult = nomfich & " a été transféré "
Else
résult = nomfich & " n'a pas pu être transféré"
End If
 
'fermer les pointeurs, ménage
InternetCloseHandle ftp_ok
InternetCloseHandle internet_ok
 
'annoncer le résultat de l'opération
If résult <> "" Then
UserForm3.Label1 = résult
UserForm3.Show
'MsgBox résult
Else
UserForm3.Label1 = "aucun fichier transféré"
UserForm3.Show
 
'MsgBox "aucun fichier transféré"
End If
 
End Sub
Pourriez-vous m'aider ?