Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Go Back  Xtreme Visual Basic Talk > > > > Upload file in website(Internet Explorer) Automation


Reply
 
Thread Tools Display Modes
  #1  
Old 10-14-2017, 03:49 AM
Javeds2cool Javeds2cool is offline
Newcomer
 
Join Date: Oct 2017
Posts: 2
Default Upload file in website(Internet Explorer) Automation


Hi,

I have a text file saved on my dekstop that I want to upload to a website automatically using a macro. There are two buttons 1)Browse-once clicked we have to select the file from respective folder. 2)Upload File.

Once we can get the file in the Browse, I can click on Upload and complete the process ?

The Inspect element codes for the browse key are as below:

<input name="filepath" ="file">
<br>
<input value="Upload File" ="Submit">
<br>
</div>

Kindly look into this and help me please.

Warm Regards,
Javed
Reply With Quote
  #2  
Old 10-16-2017, 09:11 AM
MPiUpload file in website(Internet Explorer) Automation MPi is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Dec 2001
Location: Quebec
Posts: 1,000
Default

Where are you blocked exactly ?
Do you have a piece of code and tell what does not work properly ?
__________________
MPi²
Reply With Quote
  #3  
Old 10-16-2017, 09:22 AM
Javeds2cool Javeds2cool is offline
Newcomer
 
Join Date: Oct 2017
Posts: 2
Default

Hello.

In this project, I have made a macro that goes to a website, enters some values, downloads a text file(using send keys), opens it in excel(The name the file is depending on the inputs in the website earlier-so I can fetch the file by its name), does some data manipulation and then saves it by a specific name in my dekstop. Now, the last step is to go to another website, do some selection and then click on \'Browse\' and select the file that was saved in dekstop earlier.

I have tried a couple f codes to click on browse and give the path the file that I want to upload but none them have worked so far..

The code that I have used in my macro so far:

Application.DisplayAlerts = False
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim TEXT As String
Dim ws As Worksheet
Dim stFileName As String
Dim MyObj As Object, MySource As Object, file As Variant
Dim Column As Long
Dim Rng As Range
Dim Name As String
Dim Lastrow As Long
Dim btnInput As Object ' MSHTML.HTMLInputElement
Dim ElementCol As Object ' MSHTML.IHTMLElementCollection
Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As Object
Dim FS As Object


ThisWorkbook.Sheets(1).Unprotect "khnnmuh"

'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
apiShowWindow IE.hwnd, SW_MAXIMIZE

LR = Application.WorksheetFunction.CountA(ThisWorkbook.Sheets("Sheet1").Ran ge("A:A"))

LR2 = 1

LR3 = Application.WorksheetFunction.CountA(ThisWorkbook.Sheets(2).Range("A:A "))

For Each cell In ThisWorkbook.Sheets(1).Range("A2:A" & LR).Cells
'Define URL
URL = "URL"

'Navigate to URL
IE.Navigate URL

' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."

' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until

'Webpage Loaded
Application.StatusBar = URL & " Loaded"

Set objElement = IE.document.getElementsByName("filetype")(0).getElementsByTagName("opt ion")

For Each tagx In objElement
If tagx.Value = ThisWorkbook.Sheets(1).Range("A" & cell.Row).Value Then
tagx.Selected = True
Exit For
End If
Next

Set objElement = IE.document.getElementsByName("marketplace")(0).getElementsByTagName(" option")

For Each tagx In objElement
If tagx.innerText = "NA" Then
tagx.Selected = True
Exit For
End If
Next

Set objElement = IE.document.getElementsByName("year")(0).getElementsByTagName("option" )

For Each tagx In objElement
If tagx.Value Like ThisWorkbook.Sheets(1).Cells(2, 3) Then
tagx.Selected = True
Exit For
End If
Next

Set objElement = IE.document.getElementsByName("month")(0).getElementsByTagName("option ")

For Each tagx In objElement
If tagx.Value = ThisWorkbook.Sheets(1).Cells(2, 4) Then
tagx.Selected = True
Exit For
End If
Next

Set objElement = IE.document.getElementsByName("day")(0).getElementsByTagName("option")

For Each tagx In objElement
If tagx.Value Like ThisWorkbook.Sheets(1).Cells(2, 5) Then
tagx.Selected = True
Exit For
End If
Next

Set objElement = IE.document.getElementsByName("fromhour")(0).getElementsByTagName("opt ion")

For Each tagx In objElement
If tagx.Value Like ThisWorkbook.Sheets(1).Cells(2, 6) Then
tagx.Selected = True
Exit For
End If
Next

Set objElement = IE.document.getElementsByName("tohour")(0).getElementsByTagName("optio n")

For Each tagx In objElement
If tagx.Value Like ThisWorkbook.Sheets(1).Cells(2, 7) Then
tagx.Selected = True
Exit For
End If
Next
Application.Wait Now + TimeValue("00:00:02")

Set objElement = IE.document.getElementsByTagName("Input")

For Each tagx In objElement
If tagx.Value = "Download File From S3" Then
tagx.Click
Exit For
End If
Next

Application.Wait Now + TimeValue("00:00:02")

Do Until IE.readyState = 4: DoEvents: Loop
Do While IE.Busy: DoEvents: Loop

Application.Wait Now + TimeValue("00:00:05")

IE.document.getElementsByName("filetype")(0).Focus

Application.Wait Now + TimeValue("00:00:01")

Application.SendKeys "{TAB 9}", True
Application.SendKeys "{RETURN}", True

lineagain:


ctr = 0
Set MyObj = CreateObject("Scripting.FileSystemObject")

Set MySource = MyObj.GetFolder("C:\Users" & Environ("username") & "\Downloads")
For Each file In MySource.Files

If InStr(file, ThisWorkbook.Sheets(1).Range("I" & cell.Row).Value) > 0 And Right(file, 4) = ".txt" Then
ctr = 1
Exit For
End If
Next file

If ctr = 0 Then
GoTo lineagain
End If


'End Sub
' If InStr(file, ThisWorkbook.Sheets("Inputs").Range("B" & cell.Row).Value) > 0 And InStr(file, ".xlsx.tmp") = 0 Then
'Set f = fs.GetFile(ThisWorkbook.Sheets("Inputs").Range("B1").Value & file)

Set myTextFile = Workbooks.(file)

myTextFile.Sheets(1).Range("A1").CurrentRegion.Copy _
ThisWorkbook.Sheets(2).Range("A" & LR2)
myTextFile.Close (False)

If LR2 > 1 Then
ThisWorkbook.Sheets(2).Rows(LR2).EntireRow.Delete
End If

LR2 = Application.WorksheetFunction.CountA(ThisWorkbook.Sheets(2).Range("A:A ")) + 1

Next cell

Set Rng = ThisWorkbook.Sheets(2).Rows(1).Find(What:="marketPlace", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

Range("A:AAA").AutoFilter field:=Rng.Column, Criteria1:="1"

Set Rng = ThisWorkbook.Sheets(2).Rows(1).Find(What:="Qlfr", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

Range("A:AAA").AutoFilter field:=Rng.Column, Criteria1:=Array("Rental", "TradeIn", "Used"), Operator:=xlFilterValues

Lastrow = ThisWorkbook.Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
ThisWorkbook.Sheets(2).Range("AI2:AI" & Lastrow).Value = "No Error"
ThisWorkbook.Sheets(2).Range("AH2:AH" & Lastrow).Value = ThisWorkbook.Sheets(1).Cells(2, 8)

For Each x In Range("AH2:AH" & Lastrow)
x.Value = LCase(x.Value)
Next

ThisWorkbook.Sheets(2).Columns("C").NumberFormat = "0000000000"

ThisWorkbook.Sheets(2).Columns("J").NumberFormat = "yyyy-mm-dd hh:mm:ss"

'Save Sheet 2 in .txt format

Set xwb = Workbooks.Add

Workbooks("EPI.xlsm").Activate

ThisWorkbook.Sheets(2).Range("A1:AI" & LR2).SpecialCells(xlCellTypeVisible).Copy Destination:=xwb.Sheets(1).Range("A1:AI" & LR2)

xwb.Sheets(1).SaveAs "C:\Users" & Environ("username") & "\Desktop\EPI_NA.txt", xlTextWindows
xwb.Close


'Upload the file to themis URL

'Define URL
URL = "URL2"

'Navigate to URL
IE.Navigate URL

' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."

' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until

'Webpage Loaded
Application.StatusBar = URL & " Loaded"

Set objElement = IE.document.getElementsByName("isFileRFOutput")(0).getElementsByTagNam e("option")
For Each tagx In objElement
If tagx.innerText = "EPI Audit - Non RF" Then
tagx.Selected = True
Exit For
End If
Next

'THE CODE IS WORKING FINE TILL HERE. I NEED TO CLICK ON BROWSE AND SELECT THE FILE: NA.txt THAT IS SAVED ON MY DEKSTOP.

IE.document.getElementsByName("isFileRFOutput")(0).Focus

Application.SendKeys "{TAB 1}", True
Application.SendKeys "{RETURN}", True



Set ElementCol = IE.document.getElementsByTagName("input")
For Each btnInput In ElementCol
If btnInput.Type = "file" Then
btnInput.Value = "C:\Users" & Environ("username") & "\Desktop\NA.txt"
Exit For
End If
Next btnInput

'CLick on browse and selct the file to get uploaded

Set objElement = IE.document.getElementsByName("isFileRFOutput")(0).getElementsByTagNam e("input")
For Each tagx In objElement
If tagx.Value = "filePath" Then
tagx.Click = True
Exit For
End If
Next

Set ElementCol = appIE.document.getElementsByTagName("input")
For Each btnInput In ElementCol
If btnInput.Type = "file" Then
btnInput.Value = "C:\Users" & Environ("username") & "\Desktop\NA.txt"
Exit For
End If
Next btnInput

ThisWorkbook.Sheets("Sheet1").AutoFilterMode = False
ThisWorkbook.Sheets("Sheet2").UsedRange.Clear
LineJaved:
ThisWorkbook.Sheets(1).Protect "khnnmuh", True, True
MsgBox ("Done")
'Unload IE
'Set IE = Nothing
'Set objElement = Nothing
'Set objCollection = Nothing
Application.DisplayAlerts = True
End Sub


Kindly look into this.
Reply With Quote
Reply

Tags
file, upload, browse, inspect, element, process, complete, codes, javed, click, key, warm, kindly, select, dekstop, website, saved, text, websiteinternet, explorer, automation, automatically, respective, folder, 2upload


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
 
Upload file in website(Internet Explorer) Automation
Upload file in website(Internet Explorer) Automation
 
-->