Update Hyperlinks in Microsoft Office Files

To be able to search-and-replace hyperlinks in DOCX, XLSX, and PPTX files saved by Office 2007 and later, you need to set “file formats to convert to plain text” on the File Selector panel to “writable compound documents”. This tells PowerGREP to search through the raw XML inside these files. The destination paths and URLs of hyperlinks in Office files appear as plain text inside the XML. This means you can easily replace one path or URL with another. Characters that have special meanings in XML aren’t allowed in file paths, so we don’t need to take any special care for those.

  1. Clear the file selection.
  2. Set “file formats to convert to plain text” to “writable compound documents”.
  3. Enter the file mask *.do[ct][xm];*.xls[xm];*.pptx in the “include files” box to restrict the action to Microsoft Office files.
  4. Click on the folder that contains the files you want to search through. Then select Include File or Folder or Include Folder and Subfolders from the File Selector menu.
  5. Repeat the previous step if you want to search through the files in multiple folders.
  6. Start with a fresh action.
  7. Set the action type to “search and replace”.
  8. Set the search type to “literal text”.
  9. Enter the old path into the Search box and the new path into the Replace box. You could enter \\OLDSERVER\OLDSHARE\ into the Search box and \\NEWSERVER\NEWSHARE\ into the Replace box to change all hyperlinks from the old share on the old server to the new share on the new server.
  10. Set “context type” to “search for context”. Enter the regular expression <?+[^<>]++>?+ to get one XML tag of context for hyperlinks in XML attributes, or the text between two XML tags for hyperlinks in body text. Or set “context type” to “no context” if you don’t care to see any XML.
  11. Set the target and backup file options as you like them.
  12. Click the Preview button to run a test.
  13. If all looks well, click the Replace button to actually update the hyperlinks.

An example file selection that does the first 3 steps is available in the PowerGREP5.pgl library as “Office: Search-and-replace through the raw XML inside MS Office files”.

If you have multiple sets of links that need to be updated in the same files, you can use the “list of literal text” or “delimited literal text” search type to replace all of them in a single action.