• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

need help using vba to pass data from website to Excel

nelsonwang

New Member
Hello, my excel file has a list of zip codes, and I am trying to look up these zip codes on FedEx website to determine the shipping zones, and then bring the results back to the excel file. I wrote following codes, using InternetExplorer.Application to connect to the FedEx webiste. I am able to auto populate the origin zone, destination zone fields, and figured out a way to click the "Find Zones" button, and get the zone value (in this case, zone=4). However, I am struggling how to write the code to bring the value (4) back to Excel. Any suggestion is appreciated.


Sub test()

Set objIE = CreateObject("InternetExplorer.Application")

With objIE

.Visible = True

.navigate "http://www.fedex.com/ratetools/RateToolsMain.do?method=SetupFindZones"

Do While .Busy Or _

.readyState <> 4

DoEvents

Loop

Set origin = .document.getElementsByname("origPostalCd")

origin.Item(0).Value = "83716"

Set dest = .document.getElementsByname("destPostalCd")

dest.Item(0).Value = "95050"

.document.rateToolsMainForm.target = "_parent"

.document.rateToolsMainForm.method.Value = "FindZones"

.document.rateToolsMainForm.submit

End With

End Sub
 
Hi, nelsonwang!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about your question...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


But in this case I think you're lucky as I've done something alike for Shaun a few hours ago. Here's the link to the topic:

http://chandoo.org/forums/topic/specific-data-and-html-beyond-excels-capabilities#post-92377


It accesses directly a downloaded copy of the webpage source code. You have to replace the constants ksURL, ksPrefix and ksSuffix (at least) and repeat the procedure for the two desired values, Express and Ground.


Just advise if any issue.


Regards!
 
Hi SirJB7, thank you very much for your advice and prompt response. Reading your posts and realized it is really a great idea - I never thought about copy the source code and find the values that way... the example you provided definately showed me a path to a new direction. Thanks again.


At the same time, I am just wondering if my original thought is still valid - I think the click button at the FedEx website I referred to just submit a form with 2 inputs, and returns an output of zone values. I guess the output value is saved as an attribute of something that can be passed on to the next step. Is there a way that I can find where this output value is saved and use .document.xxx.value to retrieve it directly? I am not familiar with this type of VBA codes or html codes, and I googled a lot, but cannot find any good hits. Any ideas or maybe my assumption is wrong?
 
Hi, nelsonwang!

For the first part, glad you solved it, thanks for your feedback and for your kind words too, and welcome back whenever needed or wanted.

For the second one, I wasn't able to obtain the data (from within Excel) from the FedEx Find Zone button, the form displayed differed a lot from the from retrieved by the Excel get data from the web feature, so I didn't go on digging on your original thought idea.

Regards!
 
Back
Top