L
Lee
Hi all
I have the following code which opens a dialog box and the
users can choose a document to link to BUT once the
document is clicked on and the user presses OK, the file
name of the document is not inserted
(TextToDisplay:=Selection.Text). HELP!
Sub Hyperlink()
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog
box.
Set fd = Application.FileDialog
(msoFileDialogFilePicker)
'Use a With...End With block to reference the
FileDialog object.
With fd
'Set the initial path to the Agenda Attachments
folder.
.InitialFileName
= "\\alchemy\data\processes\documents\agenda attachments\"
.Title = "Select the File to which you want to
create the link"
'Use the Show method to display the File Picker
dialog box and return the user's action.
'If the user presses the action button...
If .Show = -1 Then
ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=Selection.Text
' 'If the user presses Cancel...
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Thanks to all who helped with this code in the first
instance.
Lee
I have the following code which opens a dialog box and the
users can choose a document to link to BUT once the
document is clicked on and the user presses OK, the file
name of the document is not inserted
(TextToDisplay:=Selection.Text). HELP!
Sub Hyperlink()
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog
box.
Set fd = Application.FileDialog
(msoFileDialogFilePicker)
'Use a With...End With block to reference the
FileDialog object.
With fd
'Set the initial path to the Agenda Attachments
folder.
.InitialFileName
= "\\alchemy\data\processes\documents\agenda attachments\"
.Title = "Select the File to which you want to
create the link"
'Use the Show method to display the File Picker
dialog box and return the user's action.
'If the user presses the action button...
If .Show = -1 Then
ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=Selection.Text
' 'If the user presses Cancel...
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Thanks to all who helped with this code in the first
instance.
Lee