Hi, I would like to create a script that goes into doc/docx files and deletes the hyperlink and the hyperlink formatting. This is what I have so far -
add-type -AssemblyName "Microsoft.Office.Interop.Word" #Adding the assembly for working with word documents to allow us to change paper size and orientation later
Get-ChildItem $path -Recurse -include *.doc, *.docx | #For loop to retreve information about the documents such as their name, file path and the number of hyperlinks inside it
ForEach-Object{
$document=$application.documents.open($_.fullname) #opening the documents
write-host "Processing $($document.name)" -ForegroundColor green #letting the user know what document the script is working on currently
$objSelection = $application.Selection #select the document
$a = $objSelection.EndKey($wdStory, $wdMove)
$docprops=@{
Name=$_.Name
Path=$_.DirectoryName
LinkText=$null
LinkAddress=$null
}
$document.Hyperlinks | #for each loop working on the hyperlinks
ForEach-Object{
$docprops.LinkText=$_.TextToDisplay
$docprops.LinkAddress=$_.Address
New-Object PSObject -Property $docprops #Printing out the document properties such as hyperlink text and its address
$fpath = $document.path;
$newaddress= $fpath.SubString(0,($fpath.LastIndexOf('\')+1))
$faddress = $_.Address
}
$document.save()
$document.Close() #close the document
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($document) #Release the write lock on the Word document
}
$application.quit()
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($application) #Release the write lock on the application
This code searches for doc/docx files in the folders provided in $path/$subfolder, then opens them and searches them for hyperlinks. If they are found, print them out to screen. What I would now like to do is remove the hyperlinks found and the hyperlink formatting if that's possible?
Any Help out there?
Thanks.