+ Reply to Thread
Results 1 to 3 of 3

Using Hyperlinks within Userforms

  1. #1

    Using Hyperlinks within Userforms

    Hi all,

    I have a Userform with various command buttons in place. What I'm
    trying to do is allow users to be able to open various Word documents
    when they click on these command buttons via the use of hyperlinks
    embedded within the click event of each command button.

    So if they click on one of the command buttons it opens one Word
    document, and if they click another, it opens the second Word document
    etc. etc.

    It would be ideal to have the Userform to always remain displayed, so
    the documents open in the background, and the Userform always has the
    focus... then once the desired documents are all opened they can then
    close the Userform if they wish.

    Thanks for your help

    Karen


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Karen,

    Hyperlinks are not avaibale to the UserForm in VBA. Since you are launching Word documents from the command button click event, you can use an API call to have the system open the document. Using a few more API calls, it is easy to get the Form to stay on top of all the other documents. Add a VBA module to your workbbok and copy the code between the lines into it.
    ________________________________________________________

    'Returns the Window Handle of the Active Window
    Declare Function GetActiveWindow _
    Lib "user32.dll" () As Long

    Private Declare Function SetWindowPos _
    Lib "user32.dll" _
    (ByVal hWnd As Long, _
    ByVal hWndInsertAfter As Long, _
    ByVal X As Long, _
    ByVal Y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal wFlags As Long) As Long

    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

    Public Sub OpenFile(ByVal File_Name As String)

    Dim RetVal
    RetVal = ShellExecute(0&, "open", File_Name, vbNullString, vbNullString, 1)

    End Sub

    Public Sub KeepFormOnTop()

    Dim hWnd As Long
    Dim RetVal

    Const HWND_NOTOPMOST = -2
    Const HWND_TOPMOST = -1
    Const SWP_NOMOVE = &H2
    Const SWP_NOSIZE = &H1

    hWnd = GetActiveWindow()
    RetVal = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
    SWP_NOMOVE + SWP_NOSIZE)

    End Sub
    ________________________________________________________

    To the Command Button Click events add the following line of code:
    (You must include the Directory path along with the file name)
    Be sure to change the Directory and File name to what you are using.

    Call OpenFile("C:\Documents and Settings\Karen\My Documents\Document 1.doc")


    To the USerForm Activate event add this line of code:
    Call KeepFormOnTop

    If you have any questions, you can email at [email protected]

    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 02-14-2006 at 03:50 AM.

  3. #3

    Re: Using Hyperlinks within Userforms

    Thanks for this Leith - it all worked fine.

    Regards
    Karen


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1