excel - Web Query from URL in Cell -


i believe have thoroughly researched question (sorry if have seen answer, please patient me).

truly newcomer vba/macros , not understand "put" codes provided in these message boards, why prefer formula.

my sheet has cells feed hyperlink (i.e. a1=jfk, b1:cvg, c1=hyperlink("http://www.gcmap.com/dist?p="&a1&"-"&b1,"my flight").

if visit link (http://www.gcmap.com/dist?p=jfk-cvg) shows flying distance between these 2 points - 589 mi.

what trying do web query in excel based off link provided in cell c1, , have web query point total distance included in link - , populate cell on sheet (d1) distance.

any , appreciated!

how's this:

 sub getmiles()  'thanks http://stackoverflow.com/questions/16975506/how-to-download-source-code-from-a-website-with-vba idea dim k long, s dim url2          string dim ws worksheet, newws worksheet  set ws = activesheet   application.screenupdating = false url2 = ws.cells(1, 3) 'cell c1 url  ' data url need creat win http object_ ' tools > references > select windows win http services 5.1 dim http2         new winhttprequest 'open url http2.open "get", url2, false  ' send request http2.send 'msgbox http2.responsetext debug.print s 'debug.print http2 debug.print url2 dim resp          string: resp = http2.responsetext dim lines2        variant: lines2 = split(resp, ">")  worksheets.add after:=sheets(sheets.count) set newws = activesheet newws.name = "temp source code"  k = 0 k = lbound(lines2) ubound(lines2)     newws.cells(1 + k, 1).value = lines2(k)     k = k + 1 next k    dim findstring string, stringcell range findstring = " mi" set stringcell = newws.columns(1).find(what:=findstring)  dim milesflown    string milesflown = left(stringcell.value, worksheetfunction.search("&", stringcell, 1) - 1)  'msgbox ("you fly " & milesflown) ws.cells(1, 4).value = milesflown  application.displayalerts = false newws.delete application.displayalerts = true application.screenupdating = true  end sub 

it's sort of roundabout, source code of url, , in source code, string seems occur before miles given (" mi"), finds numbers left of &, , sets miles. need tweak macro correctly point cell url. let me know if need doing so!

edit: ah, use code, excel open, press alt+f11, open vb editor. think can insert code (just copy/paste) "sheet1 (sheet1)" part. if not, you'll need right click "vbaproject ([yourbook])" , insert module, , put code there. should show in macro list (view tab --> macros).

edit2: also, you'll need add reference in vba. press alt+f1 open vb editor, in tools -> references, "microsoft winhttp services, version 5.1" , add check mark, , click "ok" add reference. otherwise, you'll error.

edit3: updated code. puts source code on new sheet, have in col. won't deleted.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -