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: 13
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: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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: 13
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: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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: 13
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: 13
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: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
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
  #8  
Old 06-05-2017, 05:51 AM
WH7262 WH7262 is offline Windows Vista Office 2007
Novice
 
Join Date: Aug 2014
Location: Texas
Posts: 7
WH7262 is on a distinguished road
Default Sub UpdateDocuments Macro

This macro works great on .doc files, but I have .html files to work on. I tried changing the following line with .doc to .html
It worked but created a new folder for each file with the following files in that folder:
colorschememapping.xml
filelist.xml
themedata.xml
and then save each file as a .doc in the folder where the .hyml files were located

Also found that a closed parenthesis was needed at the end of (wdRDIALL
Can anyone be of some help here?

I am running Word 2010 in Bootcamp on a MAC for now, having issues with the MAC keyboard, so switched over to Bootcamp.

Thanks a lot for the macro and Kudos to Paul Edstein for creating the macro.
Reply With Quote
  #9  
Old 06-09-2017, 03:24 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

All you should need to change is:
strFile = Dir(strFolder & "\*.doc")
to:
strFile = Dir(strFolder & "\*.htm")
The saved files should retain the original format and no new files should be created.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #10  
Old 06-09-2017, 04:09 PM
WH7262 WH7262 is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Aug 2014
Location: Texas
Posts: 7
WH7262 is on a distinguished road
Default HyperLink In Multiple Documents at Once

Thanks for the suggestion, but I did as you suggested:
strFile = Dir(strFolder & "\*.doc")
to:
strFile = Dir(strFolder & "\*.htm")

But the results Is that it not only removes the hyperlinks, but also creates a folder by the same name as the .htm with _Files added and inside each folder has three filee name:
following files in that folder:
colorschememapping.xml
filelist.xml
themedata.xml

Here are the images showing this creation:
Attached Images
File Type: png Macro Results.png (171.6 KB, 8 views)
File Type: png Folders and Files Created.png (128.9 KB, 8 views)
Reply With Quote
  #11  
Old 06-13-2017, 05:38 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

In that case, the extra folders/files are a necessary part of Word's html save process. You could kill those folders post-save or save the files as plain text, then rename them post-save.
__________________
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 07:39 AM.


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