#1
|
|||
|
|||
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! |
#2
|
||||
|
||||
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 [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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! |
#4
|
||||
|
||||
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 Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Wow. Thank you so much. I really appreciate it! I'll give it a try in a bit.
|
#6
|
|||
|
|||
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. |
#7
|
||||
|
||||
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 [Fmr MS MVP - Word] |
#8
|
|||
|
|||
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. |
#9
|
||||
|
||||
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 [Fmr MS MVP - Word] |
#10
|
|||
|
|||
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: |
#11
|
||||
|
||||
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 [Fmr MS MVP - Word] |
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 |