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 / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Creating Hyperlink in Userform Text or ComboBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ffn - 28 Feb 2005 09:41 GMT
Hi there,

this may be an easy-to-solve problem but I haven't been able to find how to
do it - your help is much appreciated:

I have a template macro (invoked everytime user's selection changes) that
finds Word .doc files whose filename contains the keyword that the user has
selected.
The results of the search are then placed in either a Text or Combo box in a
persistant userform (always available in the background so user can switch
to it to view results)
The results are currently displayed as the full filename so I'm hoping to
insert the filename as a hyperlink so that the user can then click the
filename to open up the desired document - how can I accomplish this?

Also, everytime the user's selection changes the combo or text box is
"reset" and new results are inserted.

Thanks.
Jonathan West - 28 Feb 2005 09:55 GMT
> Hi there,
>
[quoted text clipped - 13 lines]
> Also, everytime the user's selection changes the combo or text box is
> "reset" and new results are inserted.

Better would be to put the result into a Label rather than a TextBox which
can be edited. You can't put hyperlinks into labels or any other control,
but you can set the events of the control so that it works as if it is a
hyperlink.

In this case, with a label, you would need to put something like this into
the Click event

Private Sub Label1_Click()
 Documents.Open Filename:=Label1.Caption
End Sub

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Tabasco Ed - 28 Feb 2005 18:16 GMT
>> Hi there,
>>
[quoted text clipped - 25 lines]
>  Documents.Open Filename:=Label1.Caption
>End Sub

Using the following, you can make a hyperlink label that will open
documents, URLs, send emails, etc.  just add the shellexecute command
of your choice into the hyperlink code.

http://vbnet.mvps.org/code/intrinsic/sehyperlink.htm
http://vbnet.mvps.org/code/shell/shellexecute.htm
ffn - 03 Mar 2005 02:14 GMT
Wow, thank you Jonathan and Tabasco Ed for the helpful replies.

I'm just wondering, is there a way to "dynamically" create labels in the
form. For example, the number of results will vary depending on the search
and can't be determined before run-time.

Cheers!

>>> Hi there,
>>>
[quoted text clipped - 16 lines]
>>> Also, everytime the user's selection changes the combo or text box is
>>> "reset" and new results are inserted.
Jonathan West - 03 Mar 2005 10:43 GMT
> Wow, thank you Jonathan and Tabasco Ed for the helpful replies.
>
> I'm just wondering, is there a way to "dynamically" create labels in the
> form. For example, the number of results will vary depending on the search
> and can't be determined before run-time.

Yes, you can dynamically create labels, but you can't dynamically create
clickable hyperlinked labels.

What you could do is create the maximum number of labels that you think you
might need, leaving them blank, and then dynamically fill them with file
names as necessary. The click event of each label would be fixed code which
reads the Caption property in order to know which file to open.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

ffn - 05 Mar 2005 07:29 GMT
Thanks Jonathan, by the way, do you have any references where I can find out
how to dynamically create labels?

cheers.

>> Wow, thank you Jonathan and Tabasco Ed for the helpful replies.
>>
[quoted text clipped - 9 lines]
> file names as necessary. The click event of each label would be fixed code
> which reads the Caption property in order to know which file to open.
Jonathan West - 09 Mar 2005 15:57 GMT
> Thanks Jonathan, by the way, do you have any references where I can find
> out how to dynamically create labels?

You can do this by means of the Controls.Add method. Assign each label you
create by this method to an object variable (perhaps an item in an array of
Labels). You can then manipulate each label as you wish (e.g. setting Top,
Left & Caption properties)

By the way, an array of controls is not the same as a VB6 Control Array (see
today's other reply in this thread.)

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Tabasco Ed - 07 Mar 2005 21:44 GMT
>> Wow, thank you Jonathan and Tabasco Ed for the helpful replies.
>>
[quoted text clipped - 4 lines]
>Yes, you can dynamically create labels, but you can't dynamically create
>clickable hyperlinked labels.

I've never tried this in VBA, but is it possible to create a control
array like in VB6?  If so, the code would already exist, you would
just add elements to the array.

>What you could do is create the maximum number of labels that you think you
>might need, leaving them blank, and then dynamically fill them with file
>names as necessary. The click event of each label would be fixed code which
>reads the Caption property in order to know which file to open.
Jonathan West - 09 Mar 2005 15:52 GMT
>>> Wow, thank you Jonathan and Tabasco Ed for the helpful replies.
>>>
[quoted text clipped - 9 lines]
> array like in VB6?  If so, the code would already exist, you would
> just add elements to the array.

Unfortunately no. Control arrays are not supported in VBA UserForms.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Jonathan West - 03 Mar 2005 12:04 GMT
> Wow, thank you Jonathan and Tabasco Ed for the helpful replies.
>
> I'm just wondering, is there a way to "dynamically" create labels in the
> form. For example, the number of results will vary depending on the search
> and can't be determined before run-time.

If you think that you might have more files than can be accommodated by
means of the label solution, a further alternative would be to put all your
filenames into a listbox. The DoubleClick event of the listbox could open
the currently-selected file. Then put a label above the listbox saying
"double-click on any item to open that file"

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

 
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.