Excel

Website Hyperlink on a form

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Justinlabenne

Description:

Using a label on a userform, provide a link to a pre-designated website. 

Discussion:

Maybe on a project you developed you would like the users to know about your website. On a userform, you can provide a quick easy link to it using a label and a bit of code. Or link to any website of your choosing, like vba express. The attached example provide 3 different formatted labels that you can use to hyperlink to a website of your choosing. 

Code:

instructions for use

			

Option Explicit Private Sub lblNavigate_Click() ' For labels with web addresses like this: ' {=============================} ' { vbaexpress.com } ' {=============================} Const szhttp As String = "http://www." ' Grab the labels caption because it contains the actual ' address of where we are heading... Dim szWebsite As String szWebsite = Me.lblNavigate.Caption ' Tie the constant and the caption into a valid address Dim szValidWebPath As String szValidWebPath = szhttp & szWebsite ' Navigate to the address... ThisWorkbook.FollowHyperlink szValidWebPath ' *Must unload form to avoid Excel freeze up Unload Me End Sub 'STANDARD MODULE: Option Explicit Sub ShowWebForm() frmWebNav.Show End Sub

How to use:

  1. Open an Excel Workbook
  2. Copy the code
  3. Press Alt + F11 to open the Visual Basic Editor (VBE)
  4. Select INSERT > USERFORM from the menubar
  5. Rename the userform: frmWebNav
  6. You will need to add:
  7. 1 Label = lblNavigate
  8. Double Click on the label
  9. Paste code into the userform code module
  10. Select INSERT > MODULE from the menubar
  11. Paste code into the right pane
  12. Copy the {ShowWebForm} code into the standard module
  13. Press Alt+Q to return to Excel
  14. Save workbook before any other changes
 

Test the code:

  1. Go to TOOLS > MACRO > MACROS
  2. Select {ShowWebForm} from the dialog box
  3. Press {Run}
  4. The userform will be displayed
  5. Click on a label to navigate to the web address listed on the label
 

Sample File:

FormLabel_web.zip 10.17KB 

Approved by mdmackillop


This entry has been viewed 183 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express