Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Code== Goto a webpage using a command button in a UserForm

I want to write a code so when I press a command button in a userform it will take me to a particular website.. Anyone know how to do this??

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

I want to write a code so when I press a command button in a userform it will
take me to a particular website.. Anyone know how to do this??

Thanks


You can do this using the ShellExecute API...


Put this in your Declaration section of the code module:
Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As
String, ByVal nShowCmd As Long) As Long


Put this in the macro that runs when you click the button:
ShellExecute 0&, vbNullString, "URL http info" vbNullString,
vbNullString, vbNormalFocus

...where the full URL is passed as a string value in the 3rd arg. Note
that the macro should be in the same code module as the API declaration
because its scope is 'Private'. If you want several sheets to use the
same API then put it in a standard module and change its scope to
'Public'.

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

Oops, a typo...

ShellExecute 0&, vbNullString, "URL http info", vbNullString,
vbNullString, vbNormalFocus

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default VBA Code== Goto a webpage using a command button in a UserForm

GS wrote:

Oops, a typo...

ShellExecute 0&, vbNullString, "URL http info", vbNullString,
vbNullString, vbNormalFocus


It should perhaps be noted that this will open the user's default browser.

--
I know the human being and fish can coexist peacefully.
-- George W. Bush
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

GS wrote:

Oops, a typo...

ShellExecute 0&, vbNullString, "URL http info", vbNullString,
vbNullString, vbNormalFocus


It should perhaps be noted that this will open the user's default browser.


Yes, I assumed this to be the best idea (in all cases) but I agree with
you that I should have mentioned it!

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default VBA Code== Goto a webpage using a command button in a UserForm

GS wrote:

GS wrote:

Oops, a typo...

ShellExecute 0&, vbNullString, "URL http info", vbNullString,
vbNullString, vbNormalFocus


It should perhaps be noted that this will open the user's default browser.


Yes, I assumed this to be the best idea (in all cases) but I agree with
you that I should have mentioned it!


Maybe not in all cases. If you have, say, documentation written in HTML that
was only tested on MSIE, then you might want to ensure that your page opens
*only* in MSIE, regardless of the user's settings.

--
Quick impression for you. Caw! Caw! Bang! ****, I'm dead!
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

GS wrote:

GS wrote:

Oops, a typo...

ShellExecute 0&, vbNullString, "URL http info", vbNullString,
vbNullString, vbNormalFocus

It should perhaps be noted that this will open the user's default browser.


Yes, I assumed this to be the best idea (in all cases) but I agree with
you that I should have mentioned it!


Maybe not in all cases. If you have, say, documentation written in HTML that
was only tested on MSIE, then you might want to ensure that your page opens
*only* in MSIE, regardless of the user's settings.


Well yes, I agree. In fact, I take this a step further in my apps that
use a HTML.EXE for a userguide in that all web links in the app open in
the EXE's browser by send it a simple command line if it's not running,
or via SendMessage if it's currently open.

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default VBA Code== Goto a webpage using a command button in a UserForm

Just to mention an alternative:

Sub Click()
ActiveWorkbook.FollowHyperlink "https://www.google.com/"
End Sub

Best wishes Harald


skrev i melding
...
I want to write a code so when I press a command button in a userform it
will take me to a particular website.. Anyone know how to do this??

Thanks



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

Just to mention an alternative:

Sub Click()
ActiveWorkbook.FollowHyperlink "https://www.google.com/"
End Sub


But of course! And ever so simple, too! Thanks for the reminder that
this is a method available in most of the MSO suite. I've put so much
focus on building reusable generic code that I've forgotten some of the
more simple approaches to some tasks.<g

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA Code== Goto a webpage using a command button in a UserForm

On Saturday, August 17, 2013 4:53:26 AM UTC-4, Harald Staff wrote:
Just to mention an alternative:



Sub Click()

ActiveWorkbook.FollowHyperlink "https://www.google.com/"

End Sub

This worked perfectly. if this is the alternative, yet works so simply, why use the first method mentioned in the first post? Thanks for all the help!

Best wishes Harald





skrev i melding

...

I want to write a code so when I press a command button in a userform it


will take me to a particular website.. Anyone know how to do this??




Thanks



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default VBA Code== Goto a webpage using a command button in a UserForm

There are times when ActiveWorkbook is Nothing and the code fails, like when
no workbooks are open, or if the active one is in "protected mode" or
something like that, new stuff. The easy for the developer, but for the user
rather confusing, workaround is

If ActiveWorkbook Is Nothing Then
Workbooks.Add (1)
Doevents
End If
ActiveWorkbook.FollowHyperlink "https://www.google.com/"

... Garry's first method is a far smoother user experience at least in those
cases.

Best wishes Harald

"Michael Davis" skrev i melding
...
On Saturday, August 17, 2013 4:53:26 AM UTC-4, Harald Staff wrote:
Just to mention an alternative:



Sub Click()

ActiveWorkbook.FollowHyperlink "https://www.google.com/"

End Sub

This worked perfectly. if this is the alternative, yet works so simply,
why use the first method mentioned in the first post? Thanks for all the
help!



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

Surely...

ThisWorkbook.FollowHyperlink

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

If anyone is interested in a reusable process that's not application
object dependant...

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long


Sub OpenUrl(Url$)
' Opens the specified URL in the user's default browser
ShellExecute 0&, vbNullString, _
Url, _
vbNullString, vbNullString, vbNormalFocus
End Sub

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default VBA Code== Goto a webpage using a command button in a UserForm

Doh! I do much of this from addins, why haven't I thought of ThisWorkbook?
Thanks Garry!

"GS" skrev i melding ...
Surely...

ThisWorkbook.FollowHyperlink

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA Code== Goto a webpage using a command button in a UserForm

Doh! I do much of this from addins, why haven't I thought of
ThisWorkbook? Thanks Garry!


Ha, ha! That's why I opted to go with the generic VB approach using
ShellExecute. It works great when using COMAddins without having to
modify it for Excel, Word, or whatever target object ref required!

A bonus is that it's portable 'as is' to my VB6.EXE stand-alone
versions of my Excel addins. (I use the FarPoint fpSpread.ocx
spreadsheet control so users don't need MS Office installed!)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
print command from command button in userform causes double chart Mike Jamesson Excel Programming 5 August 11th 09 03:42 AM
BUG: print command from command button in userform causes double c Mike Jamesson Excel Programming 0 August 10th 09 04:19 PM
command code ( GOTO command) in formula calan New Users to Excel 1 June 11th 09 09:44 AM
Userform Command Button not available until another command buttonhas been used [email protected] Excel Programming 4 September 4th 08 04:35 PM
Goto Command in Code JimPNicholls Excel Programming 2 September 1st 04 12:38 PM


All times are GMT +1. The time now is 04:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"