-2

Je me bats dans l'automatisation de téléchargement avant d'avoir essayé avec la touche d'envoi Question 1 après ma question j'ai décidé d'aller avec Windows API programme et je renvoie beaucoup de code dans le site Web que je trouve seulement, comment trouver mon "Choisissez le fichier à télécharger" Windows et cliquez sur le bouton Ouvrir, Maintenant, je ne sais pas comment insérer le chemin du fichier au nom du fichier Modifier la zone de texte dans les fenêtres ouvertes. Veuillez me dire comment définir la valeur de texte d'une zone de texte de contrôle 'edit' avec la fonction SendMessage().VBA: WIndows API: Comment assigner le chemin du fichier pour ouvrir les fenêtres?

Trouvez la capture d'écran ci-jointe pour l'explorateur de fichiers Mon explorateur IE.

enter image description here

Ci-dessous mon mentionné VBA codage FYI:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ 
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long 

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ 
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _ 
ByVal lpsz2 As String) As Long 

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ 
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 

Private Declare Function GetWindowTextLength Lib "user32" Alias _ 
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long 

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 

Const BM_CLICK = &HF5& 

Dim Ret As Long, ChildRet As Long, OpenRet As Long 
Dim strBuff As String, ButCap As String 

Sub Sample() 
    '~~> Get the handle of the "File Download" Window 
    Ret = FindWindow(vbNullString, "Choose File to Upload") 

    If Ret <> 0 Then 
     MsgBox "Main Window Found" 

     '~~> Get the handle of the Button's "Window" 
     ChildRet = FindWindowEx(Ret, ByVal 0&, "Button", vbNullString) 

     '~~> Check if we found it or not 
     If ChildRet <> 0 Then 
      MsgBox "Child Window Found" 

      '~~> Get the caption of the child window 
      strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0)) 
      GetWindowText ChildRet, strBuff, Len(strBuff) 
      ButCap = strBuff 

      '~~> Loop through all child windows 
      Do While ChildRet <> 0 
       '~~> Check if the caption has the word "Open" 
       '~~> For "Save" or "Cancel", replace "Open" with 
       '~~> "Save" or "Cancel" 
       If InStr(1, ButCap, "Open") Then 
        '~~> If this is the button we are looking for then exit 
        OpenRet = ChildRet 
        Exit Do 
       End If 

       '~~> Get the handle of the next child window 
       ChildRet = FindWindowEx(Ret, ChildRet, "Button", vbNullString) 
       '~~> Get the caption of the child window 
       strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0)) 
       GetWindowText ChildRet, strBuff, Len(strBuff) 
       ButCap = strBuff 
      Loop 

      '~~> Check if we found it or not 
      If OpenRet <> 0 Then 
       MsgBox "The Handle of Open Button is : " & OpenRet 
       '~~> Click the button using Send Message 
       SendMessage OpenRet, BM_CLICK, 0, 0 
      Else 
       MsgBox "The Handle of Open Button was not found" 
      End If 
     Else 
      MsgBox "Child Window Not Found" 
     End If 
    Else 
     MsgBox "Window Not Found" 
    End If 
End Sub 
+0

Je ne comprends pas vraiment la question. Je ne comprends pas non plus pourquoi vous devez simuler une entrée pour télécharger un fichier. Du code HTTP serait plus facile. Et si vous deviez conduire un navigateur, pourquoi n'utiliseriez-vous pas l'automatisation? –

+0

@DavidHeffernan J'essaie de télécharger automatiquement des fichiers dans saleforce site Web si VBA, donc j'ai soulevé la question et je me suis rejouée que certaines raison de sécurité ne peut pas choisir le fichier grammaticalement sur le fichier en choisissant l'explorateur avant que je puisse difficulté de codage dans le choix du fichier dans l'écran de navigation de fichiers. –

+0

Veuillez renvoyer cette question [même question] (https://social.technet.microsoft.com/Forums/windows/en-US/42d73061-dcfc-4ed2-97c3-92ba907fb5ed/automate-choose-file-to-upload- window-from-a-web-page? forum = winserverpowershell) –

Répondre

0

J'ai solution trouvée trouver le programme VBA Ouvrir la fenêtre « Faites votre choix le fichier à télécharger », cette fenêtre apparaîtra dans IE lors du téléchargement document Navigateur IE.Il sélectionnez la boîte d'édition du nom de fichier et attribuer le chemin d'accès complet du fichier et cliquez sur le bouton Ouvrir automatiquement.

Public Declare PtrSafe Function SendMessageByString Lib "user32" Alias "SendMessageA" (_ 
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long 

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _ 
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long 

Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ 
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _ 
ByVal lpsz2 As String) As Long 

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ 
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 

Private Declare Function GetWindowTextLength Lib "user32" Alias _ 
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long 


Dim strBuff As String, ButCap As String 
Public Const WM_SETTEXT = &HC 
Public Const BM_CLICK = &HF5 

Sub Sample() 
hw = FindWindow(vbNullString, "Choose File to Upload") 
op = FindWindowEx(hw, 0&, "Button", vbNullString) 

strBuff = String(GetWindowTextLength(op) + 1, Chr$(0)) 
GetWindowText op, strBuff, Len(strBuff) 
ButCap = strBuff 

    Do While op <> 0 

       If InStr(1, ButCap, "Open") Then 
        OpenRet = op 
        Exit Do 
       End If 

Loop 

hw1 = FindWindowEx(hw, 0&, "ComboBoxEx32", vbNullString) 

hw2 = FindWindowEx(hw1, 0&, "ComboBox", vbNullString) 

hw3 = FindWindowEx(hw2, 0&, "Edit", vbNullString) 

Call SendMessageByString(hw3, WM_SETTEXT, 0, "C:\Users\kkath\Documents\mine\QC\2015\MAY\Email1.pdf") 
Call SendMessage(OpenRet, BM_CLICK, 0, 0) 
End Sub