Create hyperlink in protected form

J

Jeanne

Trying to create a hyperlink/macro to an email address in a protected form -
I know how to create a hyperlink/macro so that it links to a web page - but I
don't know the command/code in visual basic to link the hyperlink to an email
address. Not sure if I have asked this correctly.
Thank you,
 
J

Jay Freedman

Jeanne said:
Trying to create a hyperlink/macro to an email address in a protected
form - I know how to create a hyperlink/macro so that it links to a
web page - but I don't know the command/code in visual basic to link
the hyperlink to an email address. Not sure if I have asked this
correctly.
Thank you,

The following macro shows how to insert the link. However, as long as the
document is protected, the link will be unusable -- clicking it won't do
anything at all.

Sub ProtectedDocMailLink()
Dim myRg As Range
Dim MailAddr As String

MailAddr = InputBox("Address:")
If Len(MailAddr) = 0 Then Exit Sub

With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If

If .Bookmarks.Exists("mail") Then
Set myRg = .Bookmarks("mail").Range

.Hyperlinks.Add Anchor:=myRg, _
Address:="mailto:" & MailAddr, _
TextToDisplay:=MailAddr
End If

.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub

You will have much better results by using the built-in command File > Send
To > Mail Recipient (As Attachment), if that's what you want to do. (In Word
2007 this is Office button > Send > EMail.) You can add that command to a
toolbar (in Word 2007, the Quick Access Toolbar) in your form's template so
it will be readily available.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jeanne

Our trainer here received this response from Microsoft:

"The setup using a MacroButton field for the hyperlink and a macro to
follow it is a Catch-22 situation. If you want the hyperlink to work,
you need the macro. If you want the macro to work, you need to have a
security level no higher than Medium.

Fortunately, there is a better solution. Place the plain vanilla
hyperlink in the document, without the MacroButton field, and insert a
continuous-type section break before and after the hyperlink (or just
one before, if the hyperlink is at the end of the document).

Open the Protect Document task pane (the lock icon on the Forms
toolbar won't do). When you select protection for forms, you should
see a blue link "Select sections..." below the dropdown; click that
and uncheck the section that contains the hyperlink. Now that
hyperlink will operate without the macro. In the VBA editor, delete
the module that contains the macro.

Test this by sending a copy to another computer where the macro
security level is High. If it complains about the macro even though it
was deleted, save the document as RTF and then open the RTF file and
save it back to .doc format; that'll clean out the remains of the
macro."

I removed the link and told the end users to either attach the document to
an email or send it like you suggested. Much easier.

Thank you for your response.

Jeanne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top