Results 1 to 7 of 7

Thread: Command Button driven hyperlinks

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    Command Button driven hyperlinks

    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.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here you go. To do an open in the deault email client substitute
    the web address with the format of "mailto:[email protected]".



    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4. (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    5. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    6.  
    7. Const SW_SHOWNORMAL = 1
    8.  
    9. Private Sub Command1_Click()
    10.     MousePointer = vbHourglass
    11.     ShellExecute Me.hwnd, vbNullString, ByVal "http://www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
    12.     MousePointer = vbNormal
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16.     Command1.Caption = "Help"
    17. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    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?
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Excel VBA version.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4. (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    5. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    6.  
    7. Const SW_SHOWNORMAL = 1
    8.  
    9. Public Sub Command1_Click()
    10.     Application.Cursor = xlWait
    11.     ShellExecute Application.hwnd, vbNullString, ByVal "http://www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
    12.     Application.Cursor = xlDefault
    13. End Sub
    14.  
    15. Private Sub Workbook_Open()
    16.     Command1.Caption = "Help"
    17. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    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...
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    The application.name property should be available in Excel 97. So
    this will work for 97+

    2000 POSTS!!!


    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4. (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    5. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    6.  
    7. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
    8. ByVal lpWindowName As String) As Long
    9.  
    10. Const SW_SHOWNORMAL = 1
    11.  
    12. Public Sub Command1_Click()
    13.     Dim lHwnd As Long
    14.     Application.Cursor = xlWait
    15.     lHwnd = FindWindow("XLMAIN", "Microsoft Excel - " & ActiveWorkbook.Name)
    16.     ShellExecute lHwnd, vbNullString, ByVal "http://www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
    17.     Application.Cursor = xlDefault
    18. End Sub
    19.  
    20. Private Sub Workbook_Open()
    21.     Command1.Caption = "Help"
    22. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158

    Thumbs up

    Originally posted by RobDog888

    2000 POSTS!!!




Posting Permissions

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



Click Here to Expand Forum to Full Width