How to extract all hyperlinks from one document?

A

avkokin

Hello.
There is the document which has many hyperlinks. I need to extract (to
copy) all these hyperlinks to new document. I use next code for this
(below). It works. Question: is this code correct or it can be turn
for the better?
Thank you very much.
The code:
Sub extractHyperlinks()
Dim oHpl As Hyperlink
Dim dAD As Document 'active document
Dim dDc As Document 'new document
Set dAD = ActiveDocument
Set dDc = Documents.Add(Visible:=False)
For Each oHpl In dAD.Hyperlinks
oHpl.Range.Copy
dDc.Activate
Selection.Paste
Selection.TypeParagraph
Next
dDc2.SaveAs "C:\Test\" & Format("hl") & ".doc"
dDc2.Close
Set dAD = Nothing
Set dDc = Nothing
End Sub
 
H

Helmut Weber

Hi Anton,

these lines shouldn't work:
dDc2.SaveAs "C:\Test\" & Format("hl") & ".doc"
dDc2.Close

as sDc2 is not declared.
Also:
Format("hl")
makes no sense.
Simply:
dDc.SaveAs "C:\Test\hl.doc"

Otherwise, I can't see anything improvable in your code.


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
A

avkokin

Hello Helmut. Thank you very much. Yes, these variable I would to
change into code - I am was hariedly. Sinserely, Anton.
 

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