Obtaining a list of all hyperlinks?
Is there some method by which a list of all hyperlinks in a Microsoft Office 2010 Document can be obtained?
I'm trying to check a large number of large documents (a grab bag of Word, Excel and PowerPoint documents) for broken links, and I'd rather not have to read every line of every document to verify that I have a list of all links.
microsoft-office
add a comment |
Is there some method by which a list of all hyperlinks in a Microsoft Office 2010 Document can be obtained?
I'm trying to check a large number of large documents (a grab bag of Word, Excel and PowerPoint documents) for broken links, and I'd rather not have to read every line of every document to verify that I have a list of all links.
microsoft-office
add a comment |
Is there some method by which a list of all hyperlinks in a Microsoft Office 2010 Document can be obtained?
I'm trying to check a large number of large documents (a grab bag of Word, Excel and PowerPoint documents) for broken links, and I'd rather not have to read every line of every document to verify that I have a list of all links.
microsoft-office
Is there some method by which a list of all hyperlinks in a Microsoft Office 2010 Document can be obtained?
I'm trying to check a large number of large documents (a grab bag of Word, Excel and PowerPoint documents) for broken links, and I'd rather not have to read every line of every document to verify that I have a list of all links.
microsoft-office
microsoft-office
asked Nov 6 '13 at 11:41
Williham TotlandWilliham Totland
3162510
3162510
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
For MS WORD,
Press Alt + F9 to display the fields
Ctrl + F to open the search box
Search: ^d hyperlink
Check "Highlight all items found ..."
Click on the Find All button
Close the dialog
Ctrl + C to copy everything that is highlighted
Open a new document and paste.
For Excel,
Close all workbooks except the one you want to find the links in.
On the Edit menu, click Find.
Click Options.
In the Find what box, enter [.
In the Within box, click Workbook.
In the Look In box, click Formulas.
Click Find All.
In the box at the bottom, look in the Formula column for formulas that contain [.
To select the cell with a link, select the row in the box at the bottom.
Links are also commonly used in names, text boxes, or chart titles.
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
|
show 1 more comment
To list all hyperlinks in a Word document:
Sub CheckLinks()
Set doc = ActiveDocument
Dim i
For i = 1 To doc.Hyperlinks.Count
Debug.Print doc.Hyperlinks(i).Address & " " & doc.Hyperlinks(i).SubAddress
Next
End Sub
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
add a comment |
I really found the answer of @user228546 helpful, as I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. However, it's a little brief, and it requires a good knowledge of Visual Basic for Applications (VBA) to get everything to work.
Here's a slightly modified answer that could help some people who don't know so much about VBA.
You'll need to get to the VBA editor using Alt+F11. Use "Insert" ->
"Module" up at the top, which will get you an editor window.
Get the Link Addresses in a New Document
I'm actually going to save the extracted hyperlinks into a new document, which I'll then save.
Type (or copy/paste) the following into the editor window.
Sub GetLinksInNewDoc()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and displays them in a new document.
'
' Declare the types of our variables
Dim doc As Document
Dim newDoc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Open a new document to put the link addresses into
Set newDoc = Documents.Add
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
' Switch into the new document
newDoc.Activate
' Put the Hyperlink Address in the new document
With Selection
.InsertAfter hlink.Address & " " & hlink.SubAddress
.InsertAfter vbNewLine
End With
Next hlink
End With
Set doc = Nothing
Set newDoc = Nothing
End Sub
Make sure that your Document with the hyperlinks is the last Microsoft Word document you had highlighted. Save your code. Either click on the green arrow to run, or from the upper toolbar select "Run" ->
"Run Sub/UserForm", or press F5
Note that you might get a "grey ghost" of the text that will eventually be in the document - something like
Get the Link Addresses in a TXT File
Now, if you actually wanted to save the URLs to a TXT
file, which is what got me to this question, you can use the same procedure, except your code should be
Sub GetLinksInTxtFile()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and outputs them to a TXT file.
' The TXT file will be written in the same directory
' as the original document
'
' Declare the types of our variables
Dim doc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Get a text file ready to which you will write the URLs
' Some old-school BASIC
Open doc.Path & "the_urls.txt" For Output As #1
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
Print #1, hlink.Address & " " & hlink.SubAddress
Next hlink
End With
Close #1
Set doc = Nothing
End Sub
I hope it helps.
Source for my understanding, outline of copying into new document.
Another related source
Source for writing to a text file (which is what I originally came searching for)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f670324%2fobtaining-a-list-of-all-hyperlinks%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
For MS WORD,
Press Alt + F9 to display the fields
Ctrl + F to open the search box
Search: ^d hyperlink
Check "Highlight all items found ..."
Click on the Find All button
Close the dialog
Ctrl + C to copy everything that is highlighted
Open a new document and paste.
For Excel,
Close all workbooks except the one you want to find the links in.
On the Edit menu, click Find.
Click Options.
In the Find what box, enter [.
In the Within box, click Workbook.
In the Look In box, click Formulas.
Click Find All.
In the box at the bottom, look in the Formula column for formulas that contain [.
To select the cell with a link, select the row in the box at the bottom.
Links are also commonly used in names, text boxes, or chart titles.
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
|
show 1 more comment
For MS WORD,
Press Alt + F9 to display the fields
Ctrl + F to open the search box
Search: ^d hyperlink
Check "Highlight all items found ..."
Click on the Find All button
Close the dialog
Ctrl + C to copy everything that is highlighted
Open a new document and paste.
For Excel,
Close all workbooks except the one you want to find the links in.
On the Edit menu, click Find.
Click Options.
In the Find what box, enter [.
In the Within box, click Workbook.
In the Look In box, click Formulas.
Click Find All.
In the box at the bottom, look in the Formula column for formulas that contain [.
To select the cell with a link, select the row in the box at the bottom.
Links are also commonly used in names, text boxes, or chart titles.
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
|
show 1 more comment
For MS WORD,
Press Alt + F9 to display the fields
Ctrl + F to open the search box
Search: ^d hyperlink
Check "Highlight all items found ..."
Click on the Find All button
Close the dialog
Ctrl + C to copy everything that is highlighted
Open a new document and paste.
For Excel,
Close all workbooks except the one you want to find the links in.
On the Edit menu, click Find.
Click Options.
In the Find what box, enter [.
In the Within box, click Workbook.
In the Look In box, click Formulas.
Click Find All.
In the box at the bottom, look in the Formula column for formulas that contain [.
To select the cell with a link, select the row in the box at the bottom.
Links are also commonly used in names, text boxes, or chart titles.
For MS WORD,
Press Alt + F9 to display the fields
Ctrl + F to open the search box
Search: ^d hyperlink
Check "Highlight all items found ..."
Click on the Find All button
Close the dialog
Ctrl + C to copy everything that is highlighted
Open a new document and paste.
For Excel,
Close all workbooks except the one you want to find the links in.
On the Edit menu, click Find.
Click Options.
In the Find what box, enter [.
In the Within box, click Workbook.
In the Look In box, click Formulas.
Click Find All.
In the box at the bottom, look in the Formula column for formulas that contain [.
To select the cell with a link, select the row in the box at the bottom.
Links are also commonly used in names, text boxes, or chart titles.
edited Nov 6 '13 at 13:27
answered Nov 6 '13 at 11:49
UnnikrishnanUnnikrishnan
1,052921
1,052921
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
|
show 1 more comment
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
This works most excellently for Word; but what of Excel and PowerPoint?
– Williham Totland
Nov 6 '13 at 12:30
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
You can use macro in excel. I have edited the answer. Plz do check.
– Unnikrishnan
Nov 6 '13 at 13:16
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
The Excel answer doesn't really answer the question: What I need is to rapidly ascertain whether or not a document contains any hyperlinks, anywhere.
– Williham Totland
Nov 6 '13 at 13:23
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
edited answer..
– Unnikrishnan
Nov 6 '13 at 13:28
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
Unfortunately, near as I can tell, the Excel answer doesn't work.
– Williham Totland
Nov 6 '13 at 14:01
|
show 1 more comment
To list all hyperlinks in a Word document:
Sub CheckLinks()
Set doc = ActiveDocument
Dim i
For i = 1 To doc.Hyperlinks.Count
Debug.Print doc.Hyperlinks(i).Address & " " & doc.Hyperlinks(i).SubAddress
Next
End Sub
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
add a comment |
To list all hyperlinks in a Word document:
Sub CheckLinks()
Set doc = ActiveDocument
Dim i
For i = 1 To doc.Hyperlinks.Count
Debug.Print doc.Hyperlinks(i).Address & " " & doc.Hyperlinks(i).SubAddress
Next
End Sub
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
add a comment |
To list all hyperlinks in a Word document:
Sub CheckLinks()
Set doc = ActiveDocument
Dim i
For i = 1 To doc.Hyperlinks.Count
Debug.Print doc.Hyperlinks(i).Address & " " & doc.Hyperlinks(i).SubAddress
Next
End Sub
To list all hyperlinks in a Word document:
Sub CheckLinks()
Set doc = ActiveDocument
Dim i
For i = 1 To doc.Hyperlinks.Count
Debug.Print doc.Hyperlinks(i).Address & " " & doc.Hyperlinks(i).SubAddress
Next
End Sub
answered Jan 26 '18 at 16:58
user228546user228546
175116
175116
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
add a comment |
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. This was the only approach that worked for me.
– bballdave025
Dec 19 '18 at 22:26
add a comment |
I really found the answer of @user228546 helpful, as I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. However, it's a little brief, and it requires a good knowledge of Visual Basic for Applications (VBA) to get everything to work.
Here's a slightly modified answer that could help some people who don't know so much about VBA.
You'll need to get to the VBA editor using Alt+F11. Use "Insert" ->
"Module" up at the top, which will get you an editor window.
Get the Link Addresses in a New Document
I'm actually going to save the extracted hyperlinks into a new document, which I'll then save.
Type (or copy/paste) the following into the editor window.
Sub GetLinksInNewDoc()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and displays them in a new document.
'
' Declare the types of our variables
Dim doc As Document
Dim newDoc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Open a new document to put the link addresses into
Set newDoc = Documents.Add
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
' Switch into the new document
newDoc.Activate
' Put the Hyperlink Address in the new document
With Selection
.InsertAfter hlink.Address & " " & hlink.SubAddress
.InsertAfter vbNewLine
End With
Next hlink
End With
Set doc = Nothing
Set newDoc = Nothing
End Sub
Make sure that your Document with the hyperlinks is the last Microsoft Word document you had highlighted. Save your code. Either click on the green arrow to run, or from the upper toolbar select "Run" ->
"Run Sub/UserForm", or press F5
Note that you might get a "grey ghost" of the text that will eventually be in the document - something like
Get the Link Addresses in a TXT File
Now, if you actually wanted to save the URLs to a TXT
file, which is what got me to this question, you can use the same procedure, except your code should be
Sub GetLinksInTxtFile()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and outputs them to a TXT file.
' The TXT file will be written in the same directory
' as the original document
'
' Declare the types of our variables
Dim doc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Get a text file ready to which you will write the URLs
' Some old-school BASIC
Open doc.Path & "the_urls.txt" For Output As #1
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
Print #1, hlink.Address & " " & hlink.SubAddress
Next hlink
End With
Close #1
Set doc = Nothing
End Sub
I hope it helps.
Source for my understanding, outline of copying into new document.
Another related source
Source for writing to a text file (which is what I originally came searching for)
add a comment |
I really found the answer of @user228546 helpful, as I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. However, it's a little brief, and it requires a good knowledge of Visual Basic for Applications (VBA) to get everything to work.
Here's a slightly modified answer that could help some people who don't know so much about VBA.
You'll need to get to the VBA editor using Alt+F11. Use "Insert" ->
"Module" up at the top, which will get you an editor window.
Get the Link Addresses in a New Document
I'm actually going to save the extracted hyperlinks into a new document, which I'll then save.
Type (or copy/paste) the following into the editor window.
Sub GetLinksInNewDoc()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and displays them in a new document.
'
' Declare the types of our variables
Dim doc As Document
Dim newDoc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Open a new document to put the link addresses into
Set newDoc = Documents.Add
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
' Switch into the new document
newDoc.Activate
' Put the Hyperlink Address in the new document
With Selection
.InsertAfter hlink.Address & " " & hlink.SubAddress
.InsertAfter vbNewLine
End With
Next hlink
End With
Set doc = Nothing
Set newDoc = Nothing
End Sub
Make sure that your Document with the hyperlinks is the last Microsoft Word document you had highlighted. Save your code. Either click on the green arrow to run, or from the upper toolbar select "Run" ->
"Run Sub/UserForm", or press F5
Note that you might get a "grey ghost" of the text that will eventually be in the document - something like
Get the Link Addresses in a TXT File
Now, if you actually wanted to save the URLs to a TXT
file, which is what got me to this question, you can use the same procedure, except your code should be
Sub GetLinksInTxtFile()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and outputs them to a TXT file.
' The TXT file will be written in the same directory
' as the original document
'
' Declare the types of our variables
Dim doc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Get a text file ready to which you will write the URLs
' Some old-school BASIC
Open doc.Path & "the_urls.txt" For Output As #1
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
Print #1, hlink.Address & " " & hlink.SubAddress
Next hlink
End With
Close #1
Set doc = Nothing
End Sub
I hope it helps.
Source for my understanding, outline of copying into new document.
Another related source
Source for writing to a text file (which is what I originally came searching for)
add a comment |
I really found the answer of @user228546 helpful, as I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. However, it's a little brief, and it requires a good knowledge of Visual Basic for Applications (VBA) to get everything to work.
Here's a slightly modified answer that could help some people who don't know so much about VBA.
You'll need to get to the VBA editor using Alt+F11. Use "Insert" ->
"Module" up at the top, which will get you an editor window.
Get the Link Addresses in a New Document
I'm actually going to save the extracted hyperlinks into a new document, which I'll then save.
Type (or copy/paste) the following into the editor window.
Sub GetLinksInNewDoc()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and displays them in a new document.
'
' Declare the types of our variables
Dim doc As Document
Dim newDoc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Open a new document to put the link addresses into
Set newDoc = Documents.Add
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
' Switch into the new document
newDoc.Activate
' Put the Hyperlink Address in the new document
With Selection
.InsertAfter hlink.Address & " " & hlink.SubAddress
.InsertAfter vbNewLine
End With
Next hlink
End With
Set doc = Nothing
Set newDoc = Nothing
End Sub
Make sure that your Document with the hyperlinks is the last Microsoft Word document you had highlighted. Save your code. Either click on the green arrow to run, or from the upper toolbar select "Run" ->
"Run Sub/UserForm", or press F5
Note that you might get a "grey ghost" of the text that will eventually be in the document - something like
Get the Link Addresses in a TXT File
Now, if you actually wanted to save the URLs to a TXT
file, which is what got me to this question, you can use the same procedure, except your code should be
Sub GetLinksInTxtFile()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and outputs them to a TXT file.
' The TXT file will be written in the same directory
' as the original document
'
' Declare the types of our variables
Dim doc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Get a text file ready to which you will write the URLs
' Some old-school BASIC
Open doc.Path & "the_urls.txt" For Output As #1
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
Print #1, hlink.Address & " " & hlink.SubAddress
Next hlink
End With
Close #1
Set doc = Nothing
End Sub
I hope it helps.
Source for my understanding, outline of copying into new document.
Another related source
Source for writing to a text file (which is what I originally came searching for)
I really found the answer of @user228546 helpful, as I could not get my version of Microsoft Word (2013) to show me the options in the accepted answer. However, it's a little brief, and it requires a good knowledge of Visual Basic for Applications (VBA) to get everything to work.
Here's a slightly modified answer that could help some people who don't know so much about VBA.
You'll need to get to the VBA editor using Alt+F11. Use "Insert" ->
"Module" up at the top, which will get you an editor window.
Get the Link Addresses in a New Document
I'm actually going to save the extracted hyperlinks into a new document, which I'll then save.
Type (or copy/paste) the following into the editor window.
Sub GetLinksInNewDoc()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and displays them in a new document.
'
' Declare the types of our variables
Dim doc As Document
Dim newDoc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Open a new document to put the link addresses into
Set newDoc = Documents.Add
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
' Switch into the new document
newDoc.Activate
' Put the Hyperlink Address in the new document
With Selection
.InsertAfter hlink.Address & " " & hlink.SubAddress
.InsertAfter vbNewLine
End With
Next hlink
End With
Set doc = Nothing
Set newDoc = Nothing
End Sub
Make sure that your Document with the hyperlinks is the last Microsoft Word document you had highlighted. Save your code. Either click on the green arrow to run, or from the upper toolbar select "Run" ->
"Run Sub/UserForm", or press F5
Note that you might get a "grey ghost" of the text that will eventually be in the document - something like
Get the Link Addresses in a TXT File
Now, if you actually wanted to save the URLs to a TXT
file, which is what got me to this question, you can use the same procedure, except your code should be
Sub GetLinksInTxtFile()
'
' Finds all hyperlinks (even with strange formats,
' as long as they're active)
' and outputs them to a TXT file.
' The TXT file will be written in the same directory
' as the original document
'
' Declare the types of our variables
Dim doc As Document
Dim hlink As Hyperlink
' Use the script on the current document
Set doc = ActiveDocument
' Get a text file ready to which you will write the URLs
' Some old-school BASIC
Open doc.Path & "the_urls.txt" For Output As #1
' Loop through all the hyperlinks using the iterable hlink variable
With doc
For Each hlink In .Hyperlinks
Print #1, hlink.Address & " " & hlink.SubAddress
Next hlink
End With
Close #1
Set doc = Nothing
End Sub
I hope it helps.
Source for my understanding, outline of copying into new document.
Another related source
Source for writing to a text file (which is what I originally came searching for)
answered Dec 19 '18 at 22:25
bballdave025bballdave025
1065
1065
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f670324%2fobtaining-a-list-of-all-hyperlinks%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown