PDA

View Full Version : Cut and Paste Hyperlinks in Word 2007



krumrei22
07-25-2011, 07:36 AM
I am new to the whole Macro word and am still learning.

I have this code:
Sub RemoveHyperlinks()Dim i As LongFor i = ActiveDocument.Hyperlinks.Count To 1 Step -1ActiveDocument.Hyperlinks(i).Delete
Next i
End Sub


However, I do not want to DELETE the Hyperlinks, I want to CUT and PASTE them to another part of the word doc.

Any help? :banghead:

Thank you!

Frosty
07-26-2011, 09:51 AM
Try using the VBA tags... much easier to read.

You haven't said where you wanted to put the hyperlinks... you'll need to determine that. This sample code will get rid of all of the hyperlinks in the document, and put them in a list at the end of the document

Sub MoveHyperlinks()
Dim i As Long
Dim rngLink As Range
Dim rngPasteHere As Range

'Cycle through all hyperlinks (going backward) in the active document
For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
'get the range of the hyperlink
Set rngLink = ActiveDocument.Hyperlinks(i).Range
'cut the range
rngLink.Cut
'now, where do you want to put it? This puts it at the end
Set rngPasteHere = ActiveDocument.Content
'put a new paragraph mark there
rngPasteHere.InsertAfter vbCr
'collapse to the end
rngPasteHere.Collapse wdCollapseEnd
'and paste
rngPasteHere.Paste
Next i
End Sub