CapnKronic
New Member
- Joined
- Feb 28, 2018
- Messages
- 2
I cannot figure this one out. When I go to upload a .csv to an online uploader, I can navigate and click every element I need. I can find the path/file and click "OPEN" and then successfully upload the file. The problem is: When the file dialog is up, VB stops, due to the dialog focus. Much like when you click the send via email button. If I close the dialog and manually re-open it, the macro runs fine.
How the heck do I bridge this gap??? I just need that last connection and I'm sure it's simple but I'm sick of searching. It's been days.
Here is the code I have made so far with some omitted areas.
This is the sub to find and open. Much of the below code was sourced from others.
How the heck do I bridge this gap??? I just need that last connection and I'm sure it's simple but I'm sick of searching. It's been days.
Here is the code I have made so far with some omitted areas.
Code:
Option Explicit
'*** Navigate and login to page
Public Sub WebX()
Dim i As Long
Dim x As String
Dim xClient, xUser, xPass, xLogin As Object
Dim xUrl, xUrlA, xUrlB, xUrlC As String
Dim xTest As String
Dim xButton1, xButton2 As Object
Set xNav = New InternetExplorer
Set ShtX = Sheets("Private")
xUrlA = "https://
xUrlB = "https://
xUrlC = "https://
xUrl = ShtX.Range("WbURL")
xNav.Visible = False
xUrl = xUrlA
xNav.navigate xUrl
LoadX ' Do Until xNav.Busy <> True And xNav.readyState = 4: DoEvents: Loop
'***Set Document Objects and variables First Time
Set xDoc = xNav.document
xTest = xNav.LocationURL
'***Check if http destination <> url location
If xUrl = xTest Then
xTimer
Dim AuthX As Boolean
AuthX = True
'****TRAVEL****
GoTo Campaigns
End If
CheckURL:
With xDoc
If xTest = xUrl Then GoTo Campaigns
Set xList = xDoc.getElementsByTagName("body")
For Each xEle In xList
If InStr(1, xEle.className, "login") <> 0 Then
OnPageTest = True
GoTo Login
'MsgBox xEle.className
i = i + 1
xEle.ID = xEle.tagName & i
End If
Next
'If OnPageTest = False Then GoTo Login
'Else
xNav.navigate xUrl
LoadX 'Do Until xNav.Busy = False And xNav.readyState = 4: DoEvents: Loop
xTest = xNav.LocationURL
'***AUTH CHECK FOR LOGIN
AuthX = False
GoTo CheckURL
End With
'***Login procedure
Login:
While AuthX = False
Set xClient = xDoc.getElementById("client_code")
Set xUser = xDoc.getElementById("user")
Set xPass = xDoc.getElementById("pass")
xClient.Value = ShtX.Range("D11").Value
xUser.Value = ShtX.Range("E11").Value
xPass.Value = ShtX.Range("F11").Value
xDoc.getElementById("loginButton").Click
LoadX 'Do Until xNav.Busy = False And xNav.readyState = 4: DoEvents: Loop
xTest = xNav.LocationURL
GoTo CheckURL
Wend
Campaigns:
Set xList = xDoc.getElementsByClassName("first-child")
For Each xEle In xList
If xEle.innerText <> vbNullString And InStr(1, xEle.innerHTML, "upload") <> 0 Then
' MsgBox xEle.innerText
i = i + 1
Set xButton1 = xEle
xEle.ID = xEle.tagName & i
End If
Next
xButton1.Click
xDoc.querySelector("*[id^='file']").Click
WinX 'sub to find and click
xDoc.querySelector("*[id^='xid name']").Checked = True
xDoc.querySelector("*[class^='xclass name']").Click
End Sub
This is the sub to find and open. Much of the below code was sourced from others.
Code:
Public Sub WinX()
Dim xPath As String
Dim CharCt As String
Dim OpenBt As String
DoEvents
'If xDoc.IsObject = True Then
' MsgBox "HTML DOC VARIABLE NOT SET"
' MsgBox "Parse .HTML Document?", 4, "*ERROR*"
' xDoc.querySelector("[id^='file']").Click
Set ShtX = Sheets("Private")
xPath = ShtX.Range("Wbpath")
xFileUP = ShtX.Range("Wbfile")
op = FindWindowEx(hw, 0&, "Button", vbNullString)
hw = FindWindow(vbNullString, "Choose File to Upload")
CharCt = String(GetWindowTextLength(op) + 1, Chr$(0))
GetWindowText op, CharCt, Len(CharCt)
OpenBt = CharCt
Do While op <> 0
If InStr(1, OpenBt, "Open") Then
OpenRet = op
Exit Do
End If
Loop
hw1 = FindWindowEx(hw, 0&, "ComboBoxEx32", vbNullString)
hw2 = FindWindowEx(hw, 0&, "ComboBox", vbNullString)
hw3 = FindWindowEx(hw2, 0&, "Edit", vbNullString)
Call SendMessageByString(hw3, WM_SETTEXT, 0, (xFileUP & xPath))
Call SendMessage(OpenRet, BM_CLICK, 0, 0)
'End If
End Sub