include document from hyperlink

G

Guest

I have many docs, created from Robohelp output, which contains links to other
docs. Is there a solution to find each hyperlink, and include the doc in the
document. On a tight deadline, and am doing each in turn Insert\Hyperlink etc.

Thanks
 
G

Graham Mayor

If your document hyperlinks when toggled (Alt+F9) look like

{ HYPERLINK "D:\\My Documents\\Test\\And data.doc" }

the following macro will change all the Hyperlink fields to IncludeText
fields and display the content. If you want them hard coded Select the
document and Press CTRL+Shift+F9 to fix the texts (or remove the apostrophe
from the start of the line

..Unlink

Sub ChangeHyperlinkField()
Dim iFld As Integer
Dim strCodes As String
Selection.HomeKey
strCodes = ActiveDocument.ActiveWindow.View.ShowFieldCodes
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
.Code.Text = replace(.Code.Text, "HYPERLINK", "INCLUDETEXT")
.Update
'.Unlink
End With
Next iFld
ActiveDocument.ActiveWindow.View.ShowFieldCodes = strCodes
End Sub

If you have a lot of documents then the following version will perform the
same task on all the Word document files in a folder. Test it with
*COPIES!!!*

Sub BatchChangeField()
Dim iFld As Integer
Dim strCodes As String
Dim FirstLoop As Boolean
Dim strFileName As String
Dim strPath As String
Dim oDoc As Document
Dim i As Long

With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
strPath = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
FirstLoop = True
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFileName = Dir$(strPath & "*.doc")
While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)

Selection.HomeKey
strCodes = ActiveDocument.ActiveWindow.View.ShowFieldCodes
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
.Code.Text = replace(.Code.Text, "HYPERLINK", "INCLUDETEXT")
.Update
.Unlink
End With
Next iFld
ActiveDocument.ActiveWindow.View.ShowFieldCodes = strCodes
oDoc.Close SaveChanges:=wdSaveChanges
Set oDoc = Nothing
GetNextDoc:
strFileName = Dir$()
Wend
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dixie Folzenlogen

If I had an index listing documents and with hyperlinks to their file
locations. How would I do a similar macro which would allow me to pick and
choose individual hyperlinked document I wanted to insert into a Word
document?
 
G

Graham Mayor

I am not sure what you are asking for here. If you click a hyperlink to a
Word document that document opens?
The macro in the thread you posted into batch converts Hyperlink fields to
include text fields and thus inserts the documents at the hyperlink
positions.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
..
 

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