Open Webpage From Excel

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Open Webpage From Excel

Post by adam »

Hi Anyone,

The following code opens the webpage mentioned in the code when the macro button is clicked. But each time the macro button is clicked it opens the same webpage in a new tab.

How could it be changed so that each time the macro button is clicked it does not open in a new tab, instead opens the webpage from the same tab.

Any help would be kindly appriciated.

Thanks in advance.

Code: Select all

Sub Google()
     ActiveWorkbook.FollowHyperlink Address:="http://www.google.com", NewWindow:=True
End Sub
The code does not work when it is changed as follows.

Code: Select all

Sub Google()
     ActiveWorkbook.FollowHyperlink Address:="http://www.google.com", NewWindow:=False
End Sub
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Webpage From Excel

Post by HansV »

The NewWindow argument doesn't do anything if you run this macro from within a workbook on disk; I think it only applies if you have a workbook in a web page.
Best wishes,
Hans

User avatar
Leif
Administrator
Posts: 7210
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Open Webpage From Excel

Post by Leif »

Leif

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

Thanks for the suggestion Leif.

By the way, like Hans said lines “The NewWindow” argument doesn't do anything if I run this macro from within a workbook on disk.

For this reason I have created a user form which when loaded displays a web page.

When the user form with the webpage is displayed, it shows the top of the web page.

Does excel has the capability to load the page on its centre with the vertical and horizontal scroll bars hidden?

I would be happy if there are any suggestions regarding this.

I’ve uploaded the workbook for further reference.
You do not have the required permissions to view the files attached to this post.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Webpage From Excel

Post by HansV »

The WebBrowser control doesn't have any properties that determine whether scroll bars are visible and which part of the web page is displayed.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

How might I do this? If I may ask
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Webpage From Excel

Post by HansV »

I don't think you can do this, so I'd concentrate on something more useful.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

Thanks for the reply.
Best Regards,
Adam

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

The WebBrowser control doesn't have any properties that determine whether scroll bars are visible and which part of the web page is displayed.
Can the scroll bars be hidden with a VBA code?
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Webpage From Excel

Post by HansV »

See the reply that you quote.
Best wishes,
Hans

User avatar
Leif
Administrator
Posts: 7210
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Open Webpage From Excel

Post by Leif »

adam wrote:
The WebBrowser control doesn't have any properties that determine whether scroll bars are visible and which part of the web page is displayed.
Can the scroll bars be hidden with a VBA code?
As Hans has stated, the WebBrowser control does not have any properties that determine whether scroll bars are visible. I don't think you are going to find code to control properties that don't exist!
Leif

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

I don't think you are not going to find code to control properties that don't exist!
But I guess the following code does remove the scroll Bars

Code: Select all

Private Sub WebBrowser1_DocumentComplete( _
ByVal pDisp As Object, _
ByRef URL As Variant _
)
WebBrowser1.Document.body.Scroll = "no"
End Sub
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Webpage From Excel

Post by HansV »

It's good that you found that. It's actually not a property of the control, but of the browser Document object; I don't know anything about that.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

Thanks for the reply. The code speeds up with the addition of the lines screenupdating false & true.
Best Regards,
Adam

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

Does excel has the capability to load the page on its center ?
can a VBA code make the webbrowser to display the center right of the web page when it is loaded. Currently it displays the top of the page.

Any suggestions please!!!???
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open Webpage From Excel

Post by HansV »

As I already mentioned, I'm not familiar with the browser Document object.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

Oh! Sorry for asking.
Best Regards,
Adam

User avatar
Leif
Administrator
Posts: 7210
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Open Webpage From Excel

Post by Leif »

Try Googling on:

WebBrowser.Document.Window.ScrollTo

- but I must admit I have no idea if it is applicable or do-able in your situation!
Leif

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open Webpage From Excel

Post by adam »

Thanks for the recommendation Leif.
I’ve uploaded the workbook with a sample website for reference.

When the website is loaded it shows the top of the page.

My intention is to load the page from the webbrowser in the userform by showing the portion of the page starting from;

"Say Hello to Kindle DX with Global Wireless"

To the text

"Read-to-Me: With the text-to-speech feature, Kindle DX can read newspapers, magazines, blogs, and books out loud to you, unless the book's rights holder made the feature unavailable"
You do not have the required permissions to view the files attached to this post.
Best Regards,
Adam

User avatar
Leif
Administrator
Posts: 7210
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Open Webpage From Excel

Post by Leif »

adam wrote:Thanks for the recommendation Leif.
I’ve uploaded the workbook with a sample website for reference.
I'm afraid I have neither the time nor the knowledge or experience to examine your/Hans' code and offer any worthwhile advice!

Did you try searching for any answers? For example (from my suggestion above):
Wrb Browser control, Hide Scrollbar and programatically scroll browser control... - VBForums
may give you some clues, although again I stress I am not really qualified to help!

From personal experience, finding the answer yourself can be much more rewarding and educational, not to mention quicker, than simply asking for the answer and not understanding what the code is doing. We at Eileen's Lounge are happy to help you learn, but there is a limit to how much you should expect volunteers to do your job for you! :smile:

(I'm mystified as to why you should want to use Excel to load a web page to plug the Kindle! Is this really the right application for what you are trying to do?)
Leif