[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.5

"File Download" Automation

Asked by rsburge in Automation, Microsoft Access Database, Visual Basic Programming

As in the related question, I am trying to automate a File download dialog from a web site, using IE automation in VBA.

The code in the related question is designed to click save and enter a file name and location etc.  I just need to alter the code to simply click the open button.

I've been able to do that (somewhat), but I think there is some extra code in here that I don't need.  Can someone please help me clean this up so that it...

1. waits for the File Download dialog to appear
2. clicks on the open button

Thanks!!
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:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
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 SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
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, ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function SetCursorPos Lib "user32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
 
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
 
Private Const WM_SETTEXT = &HC
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Const BM_CLICK = &HF5
 
 
 
Sub FileDwnld()   
 
Set xlapp = CreateObject("excel.application")
xlapp.Visible = False
Dim hwnd As Long, HWND1 As Long, HWND2 As Long, HWND3 As Long, HWND4 As Long, HWND5 As Long, HWNDCont As Long, HWNDCont1 As Long
Dim Textlen As Long, FSO As Object, Portfolio As Object
Dim Texte As String, Txt As String, I As Integer, J As Integer, K As Integer
Dim tRECT As RECT
 
 
 
        HWNDCont = 9999
         
        While HWNDCont <> 0
         
        For I = 1 To 12
         
            hwnd = FindWindow("#32770", "File Download")
            If hwnd > 0 Then
                For J = 1 To 30
                    HndB = FindWindowEx(hwnd, 0, "Button", "&Open")
                    If HndB > 0 Then
                        
                        GetWindowRect HndB, tRECT
         
                        With tRECT
                            X = .Left + (.Right - .Left) / 2
                            Y = .Top + (.Bottom - .Top) / 2
                        End With
                        
                        SetForegroundWindow hwnd
                        
                        SetCursorPos X, Y
                        'Delay 0.3
                        DoEvents
                        
                        SendMessage HndB, BM_CLICK, 0, 0
                        Exit For
                    Else
                        'Delay 0.2
                    End If
                    Debug.Print "J", J
                Next J
                Exit For
                
            Else
                'Delay 0.5
            End If
            Debug.Print "I", I
        Next I
         
        For K = 1 To 5
            hwnd = 0
            HWND1 = 0
            HWND2 = 0
            HWND3 = 0
            HWND4 = 0
            HWND5 = 0
            
            hwnd = FindWindow("#32770", "File Download")
            If hwnd > 0 And HWNDCont1 <> hwnd Then
                    HndB = FindWindowEx(hwnd, 0, "Button", "&Open")
                    HWND1 = FindWindowEx(hwnd, 0, "DUIViewWndClassName", vbNullString)
                    HWND2 = FindWindowEx(HWND1, 0, "DirectUIHWND", vbNullString)
                    HWND3 = FindWindowEx(HWND2, 0, "FloatNotifySink", vbNullString)
                    HWND4 = FindWindowEx(HWND3, 0, "Combobox", vbNullString)
                    HWND5 = FindWindowEx(HWND4, 0, "Edit", vbNullString)
         
                'filePath = "G:\aLXE-Pricing\provident\provident.csv"
                'Txt = filePath
         
                
                'deletes it if it already exists
                'If Len(Dir(Txt)) > 0 Then Kill Txt
                
                'Returns the new name and path
                'SendMessageByString HWND5, WM_SETTEXT, Len(Txt), Txt
                
                'Txt = ""
                'Click the save button
                SendMessage HndB, BM_CLICK, 0, 0
                Exit For
            Else
                HndB = FindWindowEx(hwnd, 0, "Button", "&Open")
                If HndB <> 0 Then
                        GetWindowRect HndB, tRECT
         
                        With tRECT
                            X = .Left + (.Right - .Left) / 2
                            Y = .Top + (.Bottom - .Top) / 2
                        End With
                        
                        SetForegroundWindow hwnd
                        
                        SetCursorPos X, Y
                        'Delay 0.3
                        DoEvents
                        
                        SendMessage HndB, BM_CLICK, 0, 0
                        
                        Exit For
                End If
                'Delay 0.5
            End If
            Debug.Print "K", K
        Next K
         
         
        HWNDCont = FindWindow("#32770", "File Download")
 
        Wend
    xlapp.Visible = True
End Sub
 
Related Solutions
Keywords: "File Download" Automation
 
Loading Advertisement...
 
[+][-]10/30/09 08:08 AM, ID: 25703713Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 08:43 AM, ID: 25704075Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 08:53 AM, ID: 25704177Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 08:56 AM, ID: 25704213Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 09:17 AM, ID: 25704426Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 10:08 AM, ID: 25704934Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 10:19 AM, ID: 25705039Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 11:00 AM, ID: 25705379Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 11:16 AM, ID: 25705509Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 11:37 AM, ID: 25705695Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 01:16 PM, ID: 25706437Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 03:31 PM, ID: 25707202Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 04:29 PM, ID: 25707442Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 04:42 PM, ID: 25707498Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 05:39 PM, ID: 25707774Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Automation, Microsoft Access Database, Visual Basic Programming
Sign Up Now!
Solution Provided By: egl1044
Participating Experts: 2
Solution Grade: A
 
[+][-]10/30/09 08:22 PM, ID: 25708210Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_Related_20080208