Bonjour,
J'essaie en vain d'envoyer des informations d'une page Excel vers une page Web
Mon classeur est ouvert et la page Web aussi .. je peux faire un ALT-TAB pour passer de un à l'autre. Dans la page Web, les champs à remplir n'ont pas de ID mais des noms ex.:
<td width="12%" align="right" class="field"> <input type="text" name="8+_+1" value="" size="10" maxlength="8"><input type="hidden" name="taskDataKey" value="8+_+1"><input type="hidden" name="auxTDK8+_+1" value="1302805070000"></td>
Idéalement, si la page Web n'est pas accessible par une seul ALT-TAB, j'aimerais que la macro la trouve parmi les fenêtres ouvertes (mais bon, je rêve peut-être en couleur!)
Voici mon code, qui ne marche malheureusement pas :
Private Sub CommandButton2_Click()
Dim IE As InternetExplorer
Dim elementHtml As Object
SendKeys "%{TAB}"
Set IE = activeWindows 'pas sûr du "ActiveWindows"
IE.Visible = True
Dim bOk As Boolean
Set elementHtml = IE.getElementByName("8+_+1")
If Not elementHtml Is Nothing Then
bOk = True
elementHtml.Value = ActiveSheet.Cells(9, 10).Value 'je ne suis pas sûr du format
'elementHtml.Text = ActiveSheet.Cells(9, 10).Value 'option2
'elementHtml.Value = Range("I10").Value 'option3
Else
bOk = False
End If
Set elementHtml = IE.document.getElementByName("6+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("L10").Value
End If
Set elementHtml = IE.document.getElementByName("7+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("O10").Value
End If
Set elementHtml = IE.document.getElementByName("3+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("L10").Value
End If
Set elementHtml = IE.document.getElementByName("4+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("P10").Value
End If
Set elementHtml = IE.document.getElementByName("9+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("O10").Value
End If
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{ENTER}"
DoEvents
Set IE = Nothing
If bOk Then MsgBox "Transfert réussi !" Else MsgBox "Transfert échoué!"
End Sub
J'ai eu beau chercher autant comme autant, je n'ai pas trouvé
Sauriez-vous me dire ce qui cloche dans mon code ?
Votre aide est grandement appréciée !!
J'essaie en vain d'envoyer des informations d'une page Excel vers une page Web
Mon classeur est ouvert et la page Web aussi .. je peux faire un ALT-TAB pour passer de un à l'autre. Dans la page Web, les champs à remplir n'ont pas de ID mais des noms ex.:
<td width="12%" align="right" class="field"> <input type="text" name="8+_+1" value="" size="10" maxlength="8"><input type="hidden" name="taskDataKey" value="8+_+1"><input type="hidden" name="auxTDK8+_+1" value="1302805070000"></td>
Idéalement, si la page Web n'est pas accessible par une seul ALT-TAB, j'aimerais que la macro la trouve parmi les fenêtres ouvertes (mais bon, je rêve peut-être en couleur!)
Voici mon code, qui ne marche malheureusement pas :
Private Sub CommandButton2_Click()
Dim IE As InternetExplorer
Dim elementHtml As Object
SendKeys "%{TAB}"
Set IE = activeWindows 'pas sûr du "ActiveWindows"
IE.Visible = True
Dim bOk As Boolean
Set elementHtml = IE.getElementByName("8+_+1")
If Not elementHtml Is Nothing Then
bOk = True
elementHtml.Value = ActiveSheet.Cells(9, 10).Value 'je ne suis pas sûr du format
'elementHtml.Text = ActiveSheet.Cells(9, 10).Value 'option2
'elementHtml.Value = Range("I10").Value 'option3
Else
bOk = False
End If
Set elementHtml = IE.document.getElementByName("6+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("L10").Value
End If
Set elementHtml = IE.document.getElementByName("7+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("O10").Value
End If
Set elementHtml = IE.document.getElementByName("3+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("L10").Value
End If
Set elementHtml = IE.document.getElementByName("4+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("P10").Value
End If
Set elementHtml = IE.document.getElementByName("9+_+2")
If Not elementHtml Is Nothing Then
elementHtml.Value = Range("O10").Value
End If
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{ENTER}"
DoEvents
Set IE = Nothing
If bOk Then MsgBox "Transfert réussi !" Else MsgBox "Transfert échoué!"
End Sub
J'ai eu beau chercher autant comme autant, je n'ai pas trouvé
Sauriez-vous me dire ce qui cloche dans mon code ?
Votre aide est grandement appréciée !!
Dernière édition: