Edit sharepoint list with macro - excel

I need to change the status and write comments for about 100 lists in SharePoint every week. I tried to automate it. I know how to open them in edit mode with a macro, but I don't know how to change status or how to write a comment with a macro, any ideas?
Here is my code:
Sub TT()
Dim ie(40) As Object, obj As Object
Dim cislo As String
For i = 0 To 40
If Cells(i + 2, 1).Value = "" Then
Exit Sub
End If
Set ie(i) = CreateObject("Internetexplorer.Application")
ie(i).Visible = True
ie(i).Navigate "http://adress of sharepoint list .com"
Do While ie(i).Busy
Loop
Next i
End Sub

These tutorials should give you what you need to know...excellent and well done, they show you how to do it via Listobjects and via SQL
https://www.youtube.com/watch?v=nM-gq3N6f2E
There is a series of 13 videos.

Related

Bar chart doesnt show up on Excel VBA users form

Could someone help me please? Thank you!!!!!
I have a Excel user form for supervisors to assign tasks. it has a bar chart on it to show how many items assigned to team member. the goal is to help the supervisor see how many items he assigns to each person. It works perfectly fine on my computer, but if I share it on a shared drive, my coworkers can open and use it, but the bar chart won't show. it should look like the picture.
the code is
Private Sub Assign_Invoice_cmb_AssignTo_Change()
Application.ScreenUpdating = False
Dim i As Integer
Dim RowNumber As Integer
Dim AssignChart As String
For i = 0 To Assign_Invoice_lb_Invoice.ListCount - 1
If Assign_Invoice_lb_Invoice.Selected(i) Then
Assign_Invoice_lb_Invoice.List(i, 7) = Assign_Invoice_cmb_AssignTo.Value
RowNumber = i + 15
Assign_Invoice_lb_Invoice.Selected(i) = False
End If
Next i
Call AssignInformation(Sheet2.Range("CD12").Value, Assign_Invoice_lb_Invoice, Sheet2.Range("CD9").Value, Assign_Invoice_lbl_Assigned, Assign_Invoice_lbl_NotAssigned)
Call EmbedChart("AssignChart", Assign_Invoice_img_AssignQty)
Application.ScreenUpdating = True
End Sub
Sub EmbedChart(ChartName As String, MyImage As MSForms.Image)
Dim Cname As Chart
Dim Fname As String
Fname = ThisWorkbook.Path & "\temp.gif"
Set Cname = Sheet2.ChartObjects(ChartName).Chart
Sheet2.ChartObjects(ChartName).Activate
Cname.Export Filename:=Fname, filtername:="GIF"
MyImage.Picture = LoadPicture(Fname)
End Sub
This might be due to an access issue. If the user opening it doesn't have read/write access on the shared drive, the program would not be able to save the chart image and/or wouldn't be able to display it.

How to crawl Googlemaps from VBA Excel?

As a real beginner in coding, I am looking for some help around here !
I would like to extract data from GoogleMaps: let's say, Zip code, from a company input in a cell in excel, through VBA.
As I started coding, I met difficulties at the string level as I can't target the accurate tag (here, I think, but thats the point, span) and effectively extract the zip code on the address line on Googlemaps HTML page :
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = Range("nom").Row And _
Target.Column = Range("nom").Column Then
Dim GM As New InternetExplorer
GM.Visible = True
GM.navigate "https://www.google.fr/maps/#43.3082377,5.4259519,17z?q=" & Range("nom").Value
Do
DoEvents
Loop Until GM.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = GM.document
Dim sSPAN As String
sSPAN = Trim(doc.getElementsByTagName("span")(4).innerText)
MsgBox sSPAN
End If
End Sub
Line 13 displays the following errors :
Run Titre Error 91 : object variable or with block variable not set
as I can't select the accurate block.
Following this, I have two questions:
Is it effectively possible to extract data from Google Maps ? (Through VBA or an opensource Google API, extracting from Google sheet (10000-lines excel)
Has someone ever facde this kind of difficulty ? How can I select the accurate block on Googlemaps HTML page?
This is not how I would go about it and API is definitely preferable though not via GoogleMaps unless you are building an application where you can also embed the required map.
You need a proper page load wait, a wait for the element to be present, quit the application at the end, and use a different selector strategy. You also want to implement some logic to extract the post code from address (I am not sure what view you were getting. I used a test value of Enterome):
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim t As Date, gm As New InternetExplorer
Const MAX_WAIT_SEC As Long = 10
If Target.Row = Range("nom").Row And Target.Column = Range("nom").Column Then
gm.Visible = True
gm.navigate "https://www.google.fr/maps/#43.3082377,5.4259519,17z?q=" & Range("nom").Value
While gm.Busy Or gm.readyState <> 4: DoEvents: Wend
Dim elem As Object
t = Timer
Do
On Error Resume Next
Set elem = gm.document.querySelector(".section-info-text")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While elem Is Nothing
If Not elem Is Nothing Then
MsgBox Trim$(elem.innerText)
'Implement logic to extract post code
End If
gm.Quit
End If
End Sub

How to input values into dropdown box of web page using Excel VBA

I'm trying to operate a website to display desired option chain data with an Excel VBA macro. The website -- CBOE.com -- has an input field for the ticker symbol of the desired option chains. My code has been able to drive that part of the webpage and a default option chain is displayed. It defaults to the most current month that options expire (May 2018 as of this note). From there the user can input other expiration dates for which to have other option chains (for the same symbol) to be retrieved and displayed. This is where my code seems to be breaking down.
Just above the default option chain display is a dropdown input box labeled "Expiration:" where a list of other expiration months can be selected. Once selected, a green Submit button must be clicked to get the specified option chain for the selected expiration month. Alternatively, below the default option chain are explicit filter buttons for expiration months also.
As said, my code gets to the point of specifying the symbol and getting default option chains displayed, but I can't seem to get the dropdown input field for other expiration months to work.
If anyone can see where and how my code is deficient, I'd really appreciate that insight.
Many thanks.
--Mark.
Here is my core code in question:
Sub getmarketdata_V3()
Dim mybrowser As Object, myhtml As String
Dim htmltables As Object, htmltable As Object
Dim htmlrows As Object, htmlrow As Object
Dim htmlcells As Object, htmlcell As Object
Dim xlrow As Long, xlcol As Integer
Dim exitat As Date, symbol As String
Dim flag As Integer
On Error GoTo errhdl
Const myurl = "http://www.cboe.com/delayedquote/quote-table"
symbol = UCase(Trim(Range("ticker").Text))
With Range("ticker").Worksheet
Range(Range("ticker").Offset(1, 0), Cells(Rows.Count, Range("ticker").Column + 13)).ClearContents
End With
Set mybrowser = CreateObject("internetexplorer.application")
mybrowser.Visible = True
mybrowser.navigate myurl
While mybrowser.busy Or mybrowser.readyState <> 4
DoEvents
Wend
With mybrowser.document.all
exitat = Now + TimeValue("00:00:05")
Do
.Item("ctl00$ContentTop$C002$txtSymbol").Value = symbol
.Item("ctl00$ContentTop$C002$btnSubmit").Value = "Submit"
.Item("ctl00$ContentTop$C002$btnSubmit").Click
If Err.Number = 0 Then Exit Do
Err.Clear
DoEvents
If Now > exitat Then Exit Do
Loop
End With
'This With statement is to refresh the mybrowser.document since the prior With statement pulls up a partially new webpage
With mybrowser.document.all
On Error Resume Next
exitat = Now + TimeValue("00:00:05")
'Tried using "ID" label to select desired month--in this case 2018 July is a dropdown option:
'Usind this label seems to blank out the value displayed in the dropdown input box, but does not cause
'any of the options to display nor implant "2018 July" in it either. It just remains blank and no new option
'chain is retrieved.
.Item("ContentTop_C002_ddlMonth").Select
.Item("ContentTop_C002_ddlMonth").Value = "2018 July"
.Item("ContentTop_C002_ddlMonth").Click
'Then tried using "Name" label to select desired month--in this case 2018 July is an option:
' .Item("ctl00$ContentTop$C002$ddlMonth").Value = "2018 July"
' .Item("ctl00$ContentTop$C002$ddlMonth").Click
' .Item("ctl00$ContentTop$C002$btnFilter").Value = "View Chain"
' .Item("ctl00$ContentTop$C002$btnFilter").Click
End With
While mybrowser.busy Or mybrowser.readyState <> 4
DoEvents
Wend
'Remaining logic, except for this error trap logic deals with the option chain results once it has been successfully retrieved.
'For purposes of focus on the issue of not being able to successfully have such a table displayed, that remaining process logic is not
'included here.
errhdl:
If Err.Number Then MsgBox Err.Description, vbCritical, "Get data"
On Error Resume Next
mybrowser.Quit
Set mybrowser = Nothing
Set htmltables = Nothing
End Sub
For your code:
These 2 lines change the month and click the view chain (I tested with symbol FLWS). Make sure you have sufficient delays for page to actually have loaded.
mybrowser.document.querySelector("#ContentTop_C002_ddlMonth").Value = "201809"
mybrowser.document.querySelector("#ContentTop_C002_btnFilter").Click
I found the above sketchy for timings when added into your code so I had a quick play with Selenium basic as well. Here is an example with selenium:
Option Explicit
'Tools > references > selenium type library
Public Sub GetMarketData()
Const URL As String = "http://www.cboe.com/delayedquote/quote-table"
Dim d As ChromeDriver, symbol As String
symbol = "FLWS"
Set d = New ChromeDriver
With d
.Start
.Get URL
Dim b As Object, c As Object, keys As New keys
Set b = .FindElementById("ContentTop_C002_txtSymbol")
b.SendKeys symbol
.FindElementById("ContentTop_C002_btnSubmit").Click
Set c = .FindElementById("ContentTop_C002_ddlMonth")
c.Click
c.SendKeys keys.Down 'move one month down
.FindElementById("ContentTop_C002_btnFilter").Click
Stop '<<delete me later
.Quit
End With
End Sub
Try the below approach, in case you wanna stick to IE. I tried to kick out hardcoded delay from the script. It should get you there. Make sure to fill in the text field with the appropriate ticker from the below script before execution.
There you go:
Sub HandleDropDown()
Const url As String = "http://www.cboe.com/delayedquote/quote-table"
Dim IE As New InternetExplorer, Html As HTMLDocument, post As Object, elem As Object
With IE
.Visible = True
.navigate url
While .Busy Or .readyState <> 4: DoEvents: Wend
Set Html = .document
End With
Do: Set post = Html.getElementById("ContentTop_C002_txtSymbol"): DoEvents: Loop While post Is Nothing
post.Value = "tickername" ''make sure to fill in this box with appropriate symbol
Html.getElementById("ContentTop_C002_btnSubmit").Click
Do: Set elem = Html.getElementById("ContentTop_C002_ddlMonth"): DoEvents: Loop While elem Is Nothing
elem.selectedIndex = 2 ''just select the month using it's dropdown order
Html.getElementById("ContentTop_C002_btnFilter").Click
End Sub
Reference to add to the library:
Microsoft Internet Controls
Microsoft HTML Object Library

excel vba copying fedex tracking information

I want to copy into Excel 3 tracking information tables that website generates when I track a parcel. I want to do it through Excel VBA. I can write a loop and generate this webpage for various tracking numbers. But I am having a hard time copying tables - the top table, travel history and shipments track table. Any solution? In my vba code last 3 lines below are giving an error :( - run time error '438' Object doesn't support this property or error.
Sub final()
Application.ScreenUpdating = False
Set ie = CreateObject("InternetExplorer.Application")
my_url = "https://www.fedex.com/fedextrack/index.html?tracknumbers=713418602663&cntry_code=us"
With ie
.Visible = True
.navigate my_url
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
End With
ie.document.getElementById("detailsBody").Value
ie.document.getElementById("trackLayout").Value
ie.document.getElementById("detail").Value
End Sub
.Value is not a method available in that context. also, you will want to assign the return value of the method call to a variable. Also, you should declare your variables :)
I made some modifications and include one possible way of getting data from one of the tables. YOu may need to reformat the output using TextToColumns or similar, since it prints each row in a single cell.
I also notice that when I execute this, the tables have sometimes not finished loading and the result will be an error unless you put in a suitable Wait or use some other method to determine when the data has fully loaded on the webpage. I use a simple Application.Wait
Option Explicit
Sub final()
Dim ie As Object
Dim my_url As String
Dim travelHistory As Object
Dim history As Variant
Dim h As Variant
Dim i As Long
Application.ScreenUpdating = False
Set ie = CreateObject("InternetExplorer.Application")
my_url = "https://www.fedex.com/fedextrack/index.html?tracknumbers=713418602663&cntry_code=us"
With ie
.Visible = True
.navigate my_url
'## I modified this logice a little bit:
Do While .Busy And .readyState <> 4
DoEvents
Loop
End With
'## Here is a simple method wait for IE to finish, you may need a more robust solution
' For assistance with that, please ask a NEW question.
Application.Wait Now() + TimeValue("0:00:10")
'## Get one of the tables
Set travelHistory = ie.Document.GetElementByID("travel-history")
'## Split teh table to an array
history = Split(travelHistory.innerText, vbLf)
'## Iterate the array and write each row to the worksheet
For Each h In history
Range("A1").Offset(i).Value = h
i = i + 1
Next
ie.Quit
Set ie = Nothing
End Sub

Read Data From Web Form to Excel using VBA?

I am new to VBA and I need to fetch values from this form into an Excel spreadsheet. Once the user clicks on estimate, the exchange rate is displayed. The Excel spreadsheet will have column headings matching the field names in the form.
In the form, The 'Send Amount' will be 50, 100, 500, 1000, 2500 and 7000. The 'From' Country will always be 'United States'. The worksheet should be populated with all the possible selections in the other fields of the form against 'United States' and their corresponding exchange rates.
Santosh...There are two ways of doing this
Intercept the webservice XML
Create connection to underlying DB
You need to know DB details or create COM modules in VBA for XML (which again needs server details)
if you do not know anything at all. I would suggest go to youtube and look for "VBA com connections" or "VBA XML". There are some nice videos, handing over server details on a open forum would not be an ideal thing to do
No luck here, site writes "Connecting..." eternally.But to sort out your issue, here's a sample code:Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myIE As InternetExplorer, myDoc As HTMLDocument, mySubDoc As HTMLDivElement
Dim sVal As String, lVal As Long
Set myIE = New InternetExplorer
With myIE
.Visible = True
Call .navigate("http://stackoverflow.com/")
While Not .readyState = READYSTATE_COMPLETE
DoEvents
Wend
Set myDoc = .document
End With
'SAMPLE
With mySubDoc
Set mySubDoc = myDoc.getElementsByClassName("question-summary narrow").Item(0)
sVal = CStr(mySubDoc.ID)
lVal = CLng(mySubDoc.NodeType)
Call MsgBox(sVal)
Call MsgBox(CStr(lVal))
End With
On Error Resume Next
Call mySubDoc.Close
Call myDoc.Close
Call myIE.stop
Call myIE.Quit
On Error GoTo 0
Set mySubDoc = Nothing
Set myDoc = Nothing
Set myIE = Nothing
End SubPlease note: In Excel's VBA (ALT+F11) you have to add Reference (Tools->References) to Microsoft HTML Object Library and Microsoft Internet Controls items.You can use the above guy to pick up values from the page source of the loaded page on your target site. So you have to set values you want, press the "Estimate" button, 'View Page Source' and look for the values' container node which you want to extract from VBA code (and add to your Excel VBA of course).With having your site down -ie inaccessible result page- that's all I can do but with the above code you can figure out the rest of what you have to do in Excel VBA for sure.If not, post a new question or ask here when site is up again.Hope this helps!

Resources