Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-26-2016, 11:56 AM
Jude24Joy Jude24Joy is offline Windows 8 Office 2013
Novice
 
Join Date: Dec 2016
Posts: 6
Jude24Joy is on a distinguished road
Question

Hello,



I need to remove hyperlinks from many documents at once. I've found VBA code called "KillTheHyperlinks" in several places online, but it doesn't work for me. There are two versions of that code--to kill hyperlinks in the current document, which didn't work; and to kill hyperlinks in all currently open documents. I want to run this on sometimes hundreds of files at once, so that wouldn't be very efficient for me either.

I think the solution might be in something like field.unlink? I've taken a beginner VBA class, but it's been a long time. I'm not sure how to unlink every field using VBA.

Currently, I am removing the hyperlinks by opening each document, typing ctrl-a, and then ctrl-shift-F9. There are other things I need to do to each document, but I think I've found ways to automate all of them--except for removing the hyperlinks.

I found this bit of VBA to do find and replace for multiple documents at once (https://www.extendoffice.com/documen...ple-files.html), and it works beautifully. I still need to figure out how to do multiple finds and replaces at once. I know someone posted a way deeper into that thread.

The last thing I need to do is remove the metadata. I found some freeware called Metadata Cleaner that I'm planning to download--but if there were a vba method, that would be even better.

But that's not what this thread is about, so primarily, I need to know how to remove the hyperlinks in many documents at once.

Help??

Thanks in advance!
Reply With Quote
  #2  
Old 12-26-2016, 01:17 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 14,903
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

What do you want to do with the 'removed' hyperlinks:
a) delete them and their display text entirely;
b) leave the display text behind as plain text; or
c) leave the hyperlink path behind as plain text?
Ctrl-A, Ctrl-Shift-F9 unlinks all fields in a document, not just hyperlinks, leaving behind just the displayed text.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 12-26-2016, 01:20 PM
Jude24Joy Jude24Joy is offline Windows 8 Office 2013
Novice
 
Join Date: Dec 2016
Posts: 6
Jude24Joy is on a distinguished road
Default

Everything Ctrl-A, Ctrl-Shift-F9 does is what I want--so leaving behind only the displayed text is good.

I've made a macro that will do Ctrl-A, Ctrl-Shift-F9, Save, and Close when I hit alt-w, which is faster than doing all of those steps myself, but not as fast as vba doing multiple documents all at once.

Thank you for your response!
Reply With Quote
  #4  
Old 12-26-2016, 02:55 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 14,903
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

The following macro will unlink all fields and delete metadata in all documents in a selected folder:
Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc")
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      .Fields.Unlink
      .RemoveDocumentInformation (wdRDIAll
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 12-26-2016, 08:09 PM
Jude24Joy Jude24Joy is offline Windows 8 Office 2013
Novice
 
Join Date: Dec 2016
Posts: 6
Jude24Joy is on a distinguished road
Default

Wow. Thank you so much. I really appreciate it! I'll give it a try in a bit.

Reply With Quote
  #6  
Old 12-26-2016, 10:43 PM
Jude24Joy Jude24Joy is offline Windows 8 Office 2013
Novice
 
Join Date: Dec 2016
Posts: 6
Jude24Joy is on a distinguished road
Default

This worked great! I'm much obliged! Thank you!

Is there a way to give credit/kudos/thanks to the people who help me on this forum?

Thanks!

ETA: Found the reputation scales.
Reply With Quote
  #7  
Old 12-26-2016, 11:58 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 14,903
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

Quote:
Originally Posted by Jude24Joy View Post
Is there a way to give credit/kudos/thanks to the people
There are two ways:
a) letting others know how much you appreciate the help given; and
b) using the reputation tools, which I see you've found (thanks).
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlinks: Removing Underline reRanger Word 2 08-04-2016 02:29 AM
Protected Document: Multiple Hyperlinks Andrew H Word VBA 7 11-26-2012 01:08 PM
remove multiple hyperlinks jwallace113 Word 5 03-31-2012 05:48 AM
Insert Multiple hyperlinks to word repeated in doc - easily synses Word 8 02-24-2012 05:17 AM
Hyperlinks in locked documents? Chris_S Word 0 01-26-2010 11:58 AM


All times are GMT -7. The time now is 01:58 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft