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
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:
by: thenelsonPosted on 2009-10-30 at 08:08:57ID: 25703713
You do not need API function calls to interface with internet explorer. Take a look at: Internet Explorer Automation in www.thenelson.name/#WebAcc ess for an example on how to do it. Using the code in the example, you can find the name of the objects on a page, using this code ibute("typ e") <> "" Then ibute("typ e"), "Name: " & IE.Document.all(i).getAttr ibute("nam e")
For i = 0 To IE.Document.all.length - 1
If IE.Document.all(i).getAttr
Debug.Print "Index: " & i, "Type: " & IE.Document.all(i).getAttr
End If
Next i