+ Reply to Thread
Results 1 to 15 of 15

Trying to open a website using Workbooks.Open Filename:= fails- gives back page source

  1. #1
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Trying to open a website using Workbooks.Open Filename:= fails- gives back page source

    Hi,

    This is my first post and hopefully a quite easy problem to answer
    I am trying to get excel to open a certain webpage using:

    Please Login or Register  to view this content.
    What i get in return can be seen on a screenshot below. Is there a way around this to be able to import this certain website using VBA?

    Thank you in advance

    image001.jpg
    Last edited by arlu1201; 08-14-2012 at 06:44 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Have you tried a web query?

    Or maybe a hyperlink, I'm not really sure what you're trying to do

  3. #3
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Thank you for quick reply.

    What do you mean by a web query?

    What I'm trying to do is for VBA macro to copy the web page content into excel. Instead of that, I am getting the web page source in excel. My guess is (cause some pages copy correctly) that this page has some script or css or something that excel does not recognise and can't convert as i am using an Workbooks.Open Filename:=

    Maybe there is a command that let's excel open a web page?

    If you try to run this macro you should get the same problem, though if you run it on a simpler page, it might copy the content to excel correctly

    Thanks in advance

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Why don;t you use a web query? That's what they are designed for

  5. #5
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    I need to pull the data from web through VBA, as this is only a part of the macro (i have multiple sites to draw data from, and then it is processed) and i would like to be able to do this with one click. Web query is an excel function and i don't think there is a way to use it directly with a command from VBA, is there?

    Any ideas?

    Thanks

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Yes, you can use a webquery from vba. You can generally do anything in VBA that you can do in Excel, try recording a macro whilst you do a we-query and adapt as necessary

  7. #7
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Thank you for your reply,

    After trying to do it your way and hours of searching through the net i think this has something to do with that it's a page written in PHP, so excel can see the page but cannot grab from the php app.

    on the page here: http://www.gpw.pl/portfele_indeksow/...95&lang=PL you can see that there are vertical buttons that change the content of the page. What i need is to be able to get the chart from below the button (in each "chapter") Do you know a way around excel not importing php content?

    Thank you

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Ok, the problem isn't that the page is written in php (90% of all web pages are), it's that the page loads its data through AJAX, put simply, the data isn't in the source code of the web page. This means that you can't get the data through the normal routes - WebQuery etc.

    To cut a long story short, it's not going be easy to get the data out of the page. The easiest way is probably to start automating internet explorer, so you control internet explorer through excel and return the data - it is very slow though, but it will do what you want

    Have a google around, there are loads of examples of controlling internet explorer with excel. When you get stuck, post back and we can help you out

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Here's something to get you going, it doesn't use ie so it's fast, you'll need to work out which page you want to query however:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Well at least i know what to look for thank you for pointing me in the right direction, hopefully i can find a way around this with your solution

    Cheers

    PS Thanks for posting this sample script, this will be much easier now
    Last edited by chiuauaua; 08-14-2012 at 12:18 PM.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    having tested it a bit more, my function will return data from all the tabs. It seems that the only thing that changes in the request is the long number following PL

    I don't really know how you'd find out which number to request, but the code will work for them all.

    eg: try changing the url in my code to "http://www.gpw.pl/ajaxindex.php?action=GPWPortfele&start=listForIndex&isin=PL9999999912&lang=PL"

    It rerurns the table from mWIG40 Tab to sheet1. Only the number has changed.

    Thanks for the feedback and rep

  12. #12
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Hi again,

    I had some time to play with the macro, though when i paste your text into a clean macro i get an error:

    Run-time error 91

    Object variable or With block variable not set


    When i hit debug it stays on the following line:
    For Each tr In table.Rows

    Any ideas?

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    Ok, 2 questions:

    1. Have you changed any of the code at all?
    2. Which version of IE do you have installed?

  14. #14
    Registered User
    Join Date
    08-14-2012
    Location
    Madagascar
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    nice guess

    I was testing it on an old xp machine with only IE6. On my computer (xp IE8) it works like a charm, later I will have to test it under win7 (ie9 i think) but I suppose it should work too

    Thank you

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to open a website using Workbooks.Open Filename:= fails- gives back page so

    I'm running Win7/IE9 so it works there too

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1