Open Word docs in a folder, enter password and save with password removed

  • Hi,


    I have a situation, an employee has left and gone overseas. I have about 200+ word documents that i need to open and remove the password from.


    I have the password, and all of the documents are in the same directory, what i need to do is:


    1: Open the XXX.doc
    2: Enter the password (They all have the same password)
    3: Remove the password
    4: Save the document without its password


    Is this possible with VBA?


    Thanks in advance

  • Re: Open wod docs in a folder, enter password and save with password removed


    Word VBA...



    Easiest way to remove a password on opening is to save to another file - code creates a 'SAVED' directory under the directory holding the files.


    Also removes any protection applied to elements of the document. You did not specify if that was required and cen be commented out if needed.


    Quote

    I have the password...


    Taking you at your word here - assuming there is 1 common password. Note that passwords are case sensitive.

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote from cytop;755862

    Word VBA...


    There seems to be an issue, It allows me to enter the password, It creates the "Saved" Folder but nothing gets placed into the saved folder.


    Also is there any way to expand it to look in a folder with sub folders?


    Thanks in advance

  • Re: Open wod docs in a folder, enter password and save with password removed


    Comment out the line

    Code
    ' If Err.Number = 4605 Then Resume ResumePoint


    by adding an Apostrophe at the beginning of the line, then see if any messages are displayed.


    It's pointless trying to expand this until it works for 1 directory but you really should have mentioned that to begin with as it will need to be rewritten.

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote from cytop;755902

    Comment out the line

    Code
    ' If Err.Number = 4605 Then Resume ResumePoint


    by adding an Apostrophe at the beginning of the line, then see if any messages are displayed.


    Hi,


    thanks, no errors are displayed.


    Is there possible a referance library i need to enable?


    I have the following:


    Visual Basic For Applications
    MS Excel 14.0 Object Library
    OLE Automation
    MS Office 14.0 Object Library
    MS Word 14.0 Object Library
    Windows Script Host Object Model


    Quote from cytop;755902


    It's pointless trying to expand this until it works for 1 directory but you really should have mentioned that to begin with as it will need to be rewritten.

    Apologies, i was told that the documents were all in one folder, however they didnt tell me they were in sub directories.


    Apologies again!


    Thanks for the help

  • Re: Open wod docs in a folder, enter password and save with password removed


    If you were missing a reference to a library it would simply error... Are you sure you changed the source directory as commented ...

    Code
    '// Change as needed
       vDirectory = "C:\temp\test\"


    If you did, then this version logs everything it does, try running that and view the log afterwards...


    Sample output below


    2015Sep08 08:08:37 Started
    2015Sep08 08:08:39 Password=Test
    2015Sep08 08:08:39 Source directory=C:\temp\test\
    2015Sep08 08:08:39 SAVED Directory exists
    2015Sep08 08:08:39
    2015Sep08 08:08:39 File: test1.doc
    2015Sep08 08:08:39 Opened
    2015Sep08 08:08:40 Saved as C:\temp\test\Saved\test1.doc
    2015Sep08 08:08:40 Closed
    2015Sep08 08:08:40
    2015Sep08 08:08:40 File: test1.docx
    2015Sep08 08:08:40 Opened
    2015Sep08 08:08:40 Saved as C:\temp\test\Saved\test1.docx
    2015Sep08 08:08:40 Closed
    2015Sep08 08:08:40 Finished

  • Re: Open wod docs in a folder, enter password and save with password removed



    Hi,


    This is the output i get:


    2015Sep08 17:27:01 Started
    2015Sep08 17:27:13 Password=caliber
    2015Sep08 17:27:13 Directory exists
    2015Sep08 17:27:13
    2015Sep08 17:27:13 File: ICTNWK505_AMa.doc
    2015Sep08 17:27:23 ActiveX component can't create object
    2015Sep08 17:27:23 Finished

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote from cytop;755913

    Are you running this in Word or Excel...?


    excel.....im guessing it should be work......


    Im understanding your comment "Word VBA"


    I feel like such a dumbass!!!!

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote

    I feel like such...


    Nah, we all do things like that at times. But can I reserve the right to quote you in future? :)


    Adding code in Word is the same as Excel, Alt-F11 for the VBA environment and just paste the code, cursor somewhere in the code and press F5.

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote from cytop;755915

    Nah, we all do things like that at times. But can I reserve the right to quote you in future? :)


    Adding code in Word is the same as Excel, Alt-F11 for the VBA environment and just paste the code, cursor somewhere in the code and press F5.

    Yeah,


    u can quote me on that in the future!!


    I have one last question for you, how can i attach the VBA to a command button in word, so I dont have to jump into developer to run it!


    I have the command button in my document but i cant seem to assign a macro to it like i can with excel.


    TIA

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote from cytop;755921

    ... what about the sub-directories?


    it failed with the sub dirs,



    i got this output:


    2015Sep08 18:06:22 Started
    2015Sep08 18:06:29 Password=caliber
    2015Sep08 18:06:29 Directory exists
    2015Sep08 18:06:29 Finished

  • Re: Open wod docs in a folder, enter password and save with password removed


    I know it'll fail - it wasn't written to accomodate sub-directories in multiple folders.


    Answering queries on forums like this is a little like electricity - the answers always take the path of least resistance. Sometimes (like now), the unmentioned requirement can radically affect the solution. It needs a bit of a re-write.


    Judging by the log you posted, I guess it's after 6:00pm and home time. There'll be something for you tomorrow.

  • Re: Open wod docs in a folder, enter password and save with password removed


    Quote from cytop;755923

    I know it'll fail - it wasn't written to accomodate sub-directories in multiple folders.


    Answering queries on forums like this is a little like electricity - the answers always take the path of least resistance. Sometimes (like now), the unmentioned requirement can radically affect the solution. It needs a bit of a re-write.


    Judging by the log you posted, I guess it's after 6:00pm and home time. There'll be something for you tomorrow.


    Thank you muchly sir

  • Re: Open Word docs in a folder, enter password and save with password removed


    Here you go then - it's probably a bit OTT for what you want but I had an hour free this evening...


    When you open the document, a userform will be displayed.


    First choose the starting directory (Click the '...' button in the 'Root Directory' box - it might seem a little confusing, you're lookng for a directory, not files so no files will be shown).
    Click the Sub-Folders options if you want to include them.
    Click the 'Refresh List' button to get the list of files. You may see a blank window flash on the screen - ignore.
    Once you have the list of files click the 'Start' button, You'll be asked to enter the (common) password, it'll then continue to remove the password.


    If any file happens to have a different password, you'll be given an opportunity to enter a password for that file, or you can skip it.


    The original files will be renamed to start with an '_', the files sans password will keep the original name.


    Do not run this twice on files in a directory, you'll eventually get confused as to which are the originals and which are the ones with password removed.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!