docx alsoĠ06 $passwd = Read-Host('Type in the password:')Ġ08 $textToReplace = # 'TextToFind' = 'TextToReplaceWith' and it's case sensitive.Ġ13 $word = New-Object -ComObject Word. I am not a programmer by trade so likely doing something dumb.Ĭan anyone advise please? I look forward to condescending comments :-) 001 # Find and replace in multiple word docsĠ02 # Usage: Open in ISE, update the $folderPath, change the find/replace fields in the $textToReplace array, click the run button.Ġ04 $folderPath = 'C:\Users\tim.handy\Desktop\testchangecontentsword\STANDARD DATA - Copy\CHEMICAL\ANALYSIS\01 Pre-treatment incl strippers\*' # multi-folders: 'C:\fso1*', 'C:\fso2*'Ġ05 $fileType = '*.doc' # *.doc will take all. I invoke line 96 passing in the password variable.
And this works for unrestricting a word document in Office 2010 - 2019. Tada Now you can access and change any parts of the file after you. Click 'Stop Protection' and then enter the password in the pop-up window. Line 87 then uses the variable in what I understand (I could be wrong) to be the correct format.Ġ87 $doc = $($_.FullName, $null, $false, $null, $pass, $null, $null, $pass) Open the locked Word doc, click 'Review' and select 'Restrict Editing' (in the Protect group). I have modified line 86 to pass in a password variable (requested from user I know the password (which is the same for all files). Enter a strong, unique password and press OK. I located the below Powershell code that works excellently for editing multiple Word docs, however when the docs are password protected it fails. Click on the Protect Document button and choose Encrypt with Password from the list.