L
Larry
If the document I want to create a link to is in another folder from the
present document, then, using the Insert Hyperlink Dialog box, I have to
browse for that document. Here is a quicker way to create a hyperlink
to another document, if the the other is already open in Word. I simply
open that document and run the below macro which creates a hyperlink to
that document and cuts the hyperlink to the Clipboard. Then I switch
back to the first document and paste the hyperlink. This is faster and
easier than opening the Insert Hyperlink dialog and browsing through
several folders.
Sub HyperlinkToThisDoc()
' by Larry
' Creates a hyperlink to active document and cuts it to Clipboard
' for insertion into another document.
' Set it up so document won't have to be saved afterward.
Dim bSaveState As Boolean
bSaveState = ActiveDocument.Saved
Dim r As Range
Set r = Selection.Range
Application.ScreenUpdating = False
' Go to end of document, type paragraph.
Selection.EndKey wdStory
Selection.TypeParagraph
' Print current document path.
Selection.TypeText ActiveDocument.FullName
' Select the doc path without the following para mark.
Selection.Paragraphs(1).Range.Select
Selection.MoveEndWhile cset:=Chr(13), Count:=wdBackward
' Make path small size so it won't run to two lines
' (though that doesn't matter)
With Selection.Font
.Name = "Verdana"
.Size = 8
End With
' Turn the selected document path
' into a hyperlink.
If Selection.Type <> wdSelectionIP Then
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=Trim(Selection.Text)
End If
' Select the hyperlink, unselect para mark, and cut selection.
Selection.Paragraphs(1).Range.Select
Selection.MoveEndWhile cset:=Chr(13), Count:=wdBackward
Selection.Cut
Selection.Font.Reset
Selection.TypeBackspace
' return cursor to starting point.
r.Select
' Return document to the saved state it was in at start of macro.
ActiveDocument.Saved = bSaveState
End Sub
present document, then, using the Insert Hyperlink Dialog box, I have to
browse for that document. Here is a quicker way to create a hyperlink
to another document, if the the other is already open in Word. I simply
open that document and run the below macro which creates a hyperlink to
that document and cuts the hyperlink to the Clipboard. Then I switch
back to the first document and paste the hyperlink. This is faster and
easier than opening the Insert Hyperlink dialog and browsing through
several folders.
Sub HyperlinkToThisDoc()
' by Larry
' Creates a hyperlink to active document and cuts it to Clipboard
' for insertion into another document.
' Set it up so document won't have to be saved afterward.
Dim bSaveState As Boolean
bSaveState = ActiveDocument.Saved
Dim r As Range
Set r = Selection.Range
Application.ScreenUpdating = False
' Go to end of document, type paragraph.
Selection.EndKey wdStory
Selection.TypeParagraph
' Print current document path.
Selection.TypeText ActiveDocument.FullName
' Select the doc path without the following para mark.
Selection.Paragraphs(1).Range.Select
Selection.MoveEndWhile cset:=Chr(13), Count:=wdBackward
' Make path small size so it won't run to two lines
' (though that doesn't matter)
With Selection.Font
.Name = "Verdana"
.Size = 8
End With
' Turn the selected document path
' into a hyperlink.
If Selection.Type <> wdSelectionIP Then
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:=Trim(Selection.Text)
End If
' Select the hyperlink, unselect para mark, and cut selection.
Selection.Paragraphs(1).Range.Select
Selection.MoveEndWhile cset:=Chr(13), Count:=wdBackward
Selection.Cut
Selection.Font.Reset
Selection.TypeBackspace
' return cursor to starting point.
r.Select
' Return document to the saved state it was in at start of macro.
ActiveDocument.Saved = bSaveState
End Sub