Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / February 2006

Tip: Looking for answers? Try searching our database.

Using Hyperlinks within Userforms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
assertec@aapt.net.au - 14 Feb 2006 03:26 GMT
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
Leith Ross - 14 Feb 2006 07:47 GMT
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

Sincerely,
Leith Ross

Signature

Leith Ross

assertec@aapt.net.au - 15 Feb 2006 04:56 GMT
Thanks for this Leith - it all worked fine.

Regards
Karen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.