Uploading a file to a Webpage(IE11) with Excel Macro Vba - excel

I'm trying to use the following code to upload a file to a webpage:
WD.document.getElementById("fileUpload").Value = "filepath"
'The code does not came with the property 'value' empty( = "") its just not 'there until i click the buttom "search"
'and use the popup dialog to select a file.
'Also when inserting the value by code, the source code
' returns 'value = ""' and whenever i try again,
' it still gets value = ""
WD.document.getElementById("fileUpload").Click
'The Click fires a windows popup dialog for selecting a file, so its not worthy 'to use it.
WD.document.getElementById("frmUpload").submit
'i can use this command to fire the event of uploading, but with a value = "" 'its going to return the "file not found" popup
'HERES THE SOURE CODE FOR THE SITUATION___________________:
<INPUT id=fileUpload size=48 type=file name=fileUpload>'the element
<FORM id=frmUpload encType=multipart/form-data method=post action=/ChamadoPC/Upload/12295979/1 target=fraUpload jQuery15105169442065138357="118">'the form
hope you can help me, hope everybody understand!

Related

Excel ActiveX control caption always shows question mark

I got a nasty problem with my [first] ActiveX control in Excel: the caption always shows a question mark as soon as I click anywhere outside the caption. In design mode I can change the caption to any other text, but as soon as I leave the caption, the new text is replaced by a ? .
Private Sub ×_Click()
Dummy = ActiveSheet.OLEObjects("×").Object.Caption
If Range("K27").Value = False Then
Range("K27").Value = True 'Check
ActiveSheet.OLEObjects("×").Object.Caption = ChrW(10004)
Else
Range("K27").Value = False 'UnCheck
ActiveSheet.OLEObjects("×").Object.Caption = ChrW(10008)
End If
End Sub
This macro runs perfectly and changes from ✔ to ✘ to ✔, but on afterwards clicking anywhere else on the Excel sheet it immediately becomes a ? again. Is there a way to permanently assign a default caption value ?
Thanks in advance

Trying to fill in data and click on button on Chrome browser after opening URL

I'm a using VBA Excel to try and open a URL via Chrome to fill in data and hit a submit button.
I'm able to write the command to open the URL but I am not sure how to continue to key in the data and submit the form
My Code starts as
Sub OpenHyperlinkInChrome()
Dim chromeFileLocation As String
Dim hyperlink As String
hyperlink = "<URL OVER HERE>"
chromeFileLocation = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
Shell (chromeFileLocation & "-url " & hyperlink)
driver.FindElementByName("trackingId").Value = "123"
driver.FindElementByID("epm-submit-button-announce").Click
End Sub
I get a syntax error on the "driver.FindElementByName."
My field HTML code reads as
<input type="text" placeholder="Example: BLUE_SHOES_08. This information is for your tracking purposes." name="trackingId" class="a-input-text a-span12">
The button HTML code reads as
<span id="epm-submit-button-announce" class="a-button-text a-text-center" aria-hidden="true">
Submit
</span>
How can I go about filling the form and submitting?
The problem is that you are calling the "driver" object without defining it or even declaring it.
From the code it looks like you are trying to use Selenium, have you installed Selenium?
After you install Selenium your code should look like this:
Set driver = CreateObject("Selenium.ChromeDriver")
driver.start "chrome"
driver.Get "<URL OVER HERE>"
driver.FindElementByName("trackingId").SendKeys ("123")
driver.FindElementByID("epm-submit-button-announce").Click

Excel VBA using Selenium - click on list element to change focus

I'm trying to scape data from a website via Excel VBA. I have a web page which has different data depending on a button selection, but the button sits withing a ul list. I can find the element by class using:
.FindElementByClass("shared-filter-button-list_navItem__ZiG2J")
But I can seem to work out how to switch the focus between 'This season' and 'All time' to change to displayed data on the page. Any ideas would be gratefully received. The html is:
<ul class="shared-filter-button-list_navContainer__3hJmS"><li class="shared-filter-button-list_navItem__ZiG2J is-active"><button class="tag-button_btn__1B2dI tag-button__purple__3SyTF shared-filter-button_wrap__3OgbA is-active" value="This season" type="button">This season</button></li><li class="shared-filter-button-list_navItem__ZiG2J"><button class="tag-button_btn__1B2dI tag-button__purple__3SyTF shared-filter-button_wrap__3OgbA " value="All time" type="button">All time</button></li></ul>
It would help to see the page, but if you just want to click the "this season" or "all time" button, just find the buttons inside the list you already have and click one?
update
I misread the provided HTML (its all in one line) and thought that shared-filter-button-list_navItem__ZiG2J was the container ul not the list items, and also that selenium uses 1-based indexes not 0-based.
The code below finds all buttons that match the query and prints their index and text to the debug window.
Private Driver As Selenium.ChromeDriver
Sub Main()
Set Driver = New Selenium.ChromeDriver
Driver.Get "https://www.euroleaguebasketball.net/eurocup/players/lukas-meisner/011187/"
Dim List As Selenium.WebElements
' get a list of button that are children of li with specified class name
Set List = Driver.FindElementsByXPath("//li[contains(#class, 'shared-filter-button-list_navItem__ZiG2J')]/button", 0, 5000)
If List Is Nothing Then
Debug.Print "failed to get list"
Exit Sub
End If
For Index = 1 To List.Count
Debug.Print Index & " -> " & List(Index).Text
Next Index
End Sub
Expected result from this code is:
1 -> This season
2 -> All time
3 -> Regular Season
If you wanted to click the This season button
List(1).Click

Excel VBA Ribbon - Set value of editBox on Startup Based on Value on Worksheet

I have an editBox on an Excel File where I want to display a date that is stored in a named cell on a specific worksheet. I want this value to be displayed when the Excel file is opened.
Here's the ribbon XML line:
<editBox id="editBoxSDate" label = "S Date" onChange = "onChange_SDate" getText = "getText_SDate"/>
Here's the getText_SDate function:
Public Function getText_SDate(ByRef control As Office.IRibbonControl) As String
getText_SDate = CStr(wksSettings.Range("SettingsSDate"))
End Function
When I open the file and click on my custom Ribbon tab, I get the following error message:
Wrong number of arguments or invalid property assignment
What am I missing or doing wrong?
Either change the name of the Function or the getText command to match, actually they do not match, i.e.: getText_Date vs.getText_SDate

code runs differently with/without breakpoint

I'm creating a user form (with SAVE button that writes to Excel sheet and RETURN button that goes back to a splash page) and want to set/check a flag if there are unsaved changes on the form. I'm getting different functionality of the code depending on whether a breakpoint is set or not.
Here is the relevant portion of code:
Public saveFlag as Boolean
Private Sub UserForm_Initialize()
initializeCMAValues Me
initializeTeamValues Me, getRowNum("CMA", "Team", False)
' getRowNum is a function that returns the row to read from
' in this case, the row with name=CMA, type=Team, createRow=False
saveFlag = False
End Sub
Private Sub btn_Return_Click()
' Check for unsaved data
If saveFlag Then
If MsgBox("You have unsaved information on the form. Do you wish to save it?", vbYesNo, "Unsaved Data") = vbYes Then
btn_Save_Click
End If
End If
' Return to splash form
Unload Me
Form_Splash.Show
End Sub
If I enter the form and select RETURN, I get the msgbox prompt. If I set a breakpoint at the saveFlag = False line, enter form, select RETURN (invoking breakpoint), continue running, then it runs as I would expect (i.e., no msgbox).
Instead of a public saveFlag variable, I've tried writing the flag to a non-visible label on the form; I've also tried writing to a cell on the Excel sheet. Both gave the same results of this different behavior with and without the breakpoint.
I've also run the code with the initializeTeamValues line commented out and then the code runs fine. I've triple checked that this subroutine only fills values into the textboxes on the form, nothing else.
Some research turned up a vague answer related to OLE pushing values onto the stack. I then tried putting the "saveFlag = False" line at the beginning of the subroutine. Same results.
Ideas of why the varying behavior? Is there a better/alternate way to check for unsaved data?

Resources