PDA

Click to See Complete Forum and Search --> : Command Button driven hyperlinks


TheFIDDLER
Apr 25th, 2004, 08:20 AM
Simple question here.

I have a command button. I would like it to simulate a hyperlink. Hence I want to code a web page address, and it would move to that web page address.

Is there a simple method of doing this. I do not want to add extra references to my project. Or code for the opening of the web page editor.

I like the hyperlink concept, where the system opens either a web broswer or an email depending on the address stored.

- My help files are all done in html. I want to incorporate a HELP button in my application that would open my files in IE or whatever browser the user has installed on his system.

RobDog888
Apr 25th, 2004, 07:47 PM
Here you go. To do an open in the deault email client substitute
the web address with the format of "mailto:johndoe@doe.com".

:)

Option Explicit

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

Const SW_SHOWNORMAL = 1

Private Sub Command1_Click()
MousePointer = vbHourglass
ShellExecute Me.hwnd, vbNullString, ByVal "http://www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
MousePointer = vbNormal
End Sub

Private Sub Form_Load()
Command1.Caption = "Help"
End Sub

TheFIDDLER
Apr 25th, 2004, 10:02 PM
me.hwnd ?

I get a compile error. Method or data member not found.
What is your "me"? Are you running this from a form? Are you putting any of your code in a class module?

RobDog888
Apr 26th, 2004, 12:17 AM
Excel VBA version.
Option Explicit

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

Const SW_SHOWNORMAL = 1

Public Sub Command1_Click()
Application.Cursor = xlWait
ShellExecute Application.hwnd, vbNullString, ByVal "http://www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
Application.Cursor = xlDefault
End Sub

Private Sub Workbook_Open()
Command1.Caption = "Help"
End Sub

TheFIDDLER
Apr 26th, 2004, 06:31 PM
Thanks !

I got it working in XL02.

I XL97, I get a object not supported message box in response to your application.hwnd command.

Humm, still looking for a a code routine that is universal to all Excel versions. There must have been a quick and easy way to reference a web page in 97. Hyperlinks can do it so easily so we must be able to code hyperlinks. Any suggestions...

RobDog888
Apr 26th, 2004, 10:43 PM
The application.name property should be available in Excel 97. So
this will work for 97+

2000 POSTS!!!
:D :D :D :D :D

Option Explicit

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

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Const SW_SHOWNORMAL = 1

Public Sub Command1_Click()
Dim lHwnd As Long
Application.Cursor = xlWait
lHwnd = FindWindow("XLMAIN", "Microsoft Excel - " & ActiveWorkbook.Name)
ShellExecute lHwnd, vbNullString, ByVal "http://www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
Application.Cursor = xlDefault
End Sub

Private Sub Workbook_Open()
Command1.Caption = "Help"
End Sub

Garratt
Apr 26th, 2004, 11:39 PM
Originally posted by RobDog888

2000 POSTS!!!
:D :D :D :D :D




:afrog: :thumb: :wave: ;)