Encrypt a Word document in VBA

I want to create a macro that in certain situations will encrypt the current 
document such that when the document is saved and opened again, Word will ask 
for the password (similarly to the user selecting the Office Button -> 
Prepare -> Encrypt Document). 

Would someone tell me how this can be done?  Thanks for any help.

0
Utf
6/1/2010 2:19:01 PM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
3541 Views

Similar Articles

[PageSpeed] 59

To set a password ...

    ActiveDocument.Password = "whatever"

To save with a password ...

    ActiveDocument.SaveAs name_etc., Password:="whatever"

-- 
Enjoy,
Tony

 www.WordArticles.com

"JeffG" <JeffG@discussions.microsoft.com> wrote in message 
news:00FD01C1-E5E9-4D8B-98C2-28E616BDFFED@microsoft.com...
>I want to create a macro that in certain situations will encrypt the 
>current
> document such that when the document is saved and opened again, Word will 
> ask
> for the password (similarly to the user selecting the Office Button ->
> Prepare -> Encrypt Document).
>
> Would someone tell me how this can be done?  Thanks for any help.
> 

0
Tony
6/1/2010 3:43:21 PM
Thanks for the response.  That worked beautifully, but raises another 
question.  how good is the encryption and how easily can it be broken?

"Tony Jollans" wrote:

> To set a password ...
> 
>     ActiveDocument.Password = "whatever"
> 
> To save with a password ...
> 
>     ActiveDocument.SaveAs name_etc., Password:="whatever"
> 
> -- 
> Enjoy,
> Tony
> 
>  www.WordArticles.com
> 
> "JeffG" <JeffG@discussions.microsoft.com> wrote in message 
> news:00FD01C1-E5E9-4D8B-98C2-28E616BDFFED@microsoft.com...
> >I want to create a macro that in certain situations will encrypt the 
> >current
> > document such that when the document is saved and opened again, Word will 
> > ask
> > for the password (similarly to the user selecting the Office Button ->
> > Prepare -> Encrypt Document).
> >
> > Would someone tell me how this can be done?  Thanks for any help.
> > 
> 
> .
> 
0
Utf
6/2/2010 12:40:01 PM
If you use a strong password, it will be strong.  If you use a weak one, it 
will be weak.

The stronger the password, the stronger the protection.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"JeffG" <JeffG@discussions.microsoft.com> wrote in message 
news:EC7C5616-1AAE-4AE4-A00B-74F099A15BC1@microsoft.com...
> Thanks for the response.  That worked beautifully, but raises another
> question.  how good is the encryption and how easily can it be broken?
>
> "Tony Jollans" wrote:
>
>> To set a password ...
>>
>>     ActiveDocument.Password = "whatever"
>>
>> To save with a password ...
>>
>>     ActiveDocument.SaveAs name_etc., Password:="whatever"
>>
>> -- 
>> Enjoy,
>> Tony
>>
>>  www.WordArticles.com
>>
>> "JeffG" <JeffG@discussions.microsoft.com> wrote in message
>> news:00FD01C1-E5E9-4D8B-98C2-28E616BDFFED@microsoft.com...
>> >I want to create a macro that in certain situations will encrypt the
>> >current
>> > document such that when the document is saved and opened again, Word 
>> > will
>> > ask
>> > for the password (similarly to the user selecting the Office Button ->
>> > Prepare -> Encrypt Document).
>> >
>> > Would someone tell me how this can be done?  Thanks for any help.
>> >
>>
>> .
>> 
0
Doug
6/2/2010 10:59:30 PM
Reply:

Similar Artilces:

Embedded word doc changed to image-need to change back to word.
I have an embedded word document that misteriously changed into an image. This image is not a word doc converted into a picture (i.e. like I convert an embedded word doc by right clicking and selecting 'image object', 'covert', and then select to activate as a word doc.) but an actual image as if I inserted a picture. Need to turn the image back into a word doc so I can recover my work. It would also be nice to figure out how I am changing to an image, amost seems like a bug since it has randomly happened twice. ...

Resize a document
Hello, I would like to resize a publisher document 8.5 x 11...to 7 x 9 without disrupting the layout. Any ideas? Hi Tina (anonymous@discussions.microsoft.com), in the Microsoft� newsgroups you posted: || Hello, I would like to resize a publisher document 8.5 x || 11...to 7 x 9 without disrupting the layout. Any ideas? The only options really are to: 1. Create a new publication with the sizes you prefer. 2. Change the page size of your publication, then select all objects on the page, group them, then resize as a group. Items such as text and text in tables will not resize properly. You w...

AutoFormat not working in Word 2007 in Windows 7
I have just installed the Office 2007 suite on Windows 7 Professional, 64-bit edition. Almost everything works well, but I noticed that when I type quotes, Word 2007 is not automatically converting them from straight quotes to curly quotes. I have went into the Word Options and tried the setting both ways, but it makes no difference. I have made absolutely no changes to this installation, and this problem does not occur on my Windows Vista and Windows XP machines. The computer is virus-free (I have an antivirus solution running, I don't go to shady sites to begin with...

Lost ability in MSWord to make ANY changes to ANY document
Somehow when I open a document in Word, it will not let me do anything other than open the document, print and close, everything else come up 'faded'- I can't even make changes anymore, and i've tried restoring my system to an earlier date, but nothing- Version of Word? If it's 2007 and someplace on the screen it says something about "This modification is not allowed because selection is locked", it could be that you've been using a trial version that's now expired or you haven't properly activated your full version. -- Cheers! Gor...

MAPI Failure message using 2007 word
-- JOHN HASKINS I keep getting this error message when I try to send a document from Word 2007 to my Outlook Email Client, which is my default email setup. I followed the recommended steps that help feature suggested, but that did not work by saving the document then closing and also closing Outlook, which was when word would restart it would start a new MAPI Session. No Go! What much I do. All other applications and software allow me to send to my email client except Office. ...

a document has gone in compatibility mode how do I get it back
I lost a couple of documents that I had saved and was changing the saved title and as I have said the document has gone into compatibility and I cant get it back. ...

Macro or VBA
I am dumb, but would like to automatically trim down reports that we get from our IT dept. We have to delete redundant columns (A,B,C,D,E,G,H,J,K)from each report. In other words, the only data we want to view is in F,I,J,P. Can this done more effciently with a macro or VBA/ Could someone give me an example of either so that I could work from and learn? Thank-You start a new workbook open one of those report workbooks record a macro into that new workbook (not the report workbook) when you delete the columns you don't want. stop recording back to that new workbook save it as a nice...

How do you search within a document?
I am woundering how you search with in a saved document. I want to make a spread sheet for my buisness on my supplies, my cost, and my mark up cost but there is over 200 so I was woundering how i can go into this saved document and just type in the item I am looking for and have it pop up with out having to scroll throu the list? The first thing you should look at is Data>Filter. It may well do everything you want. If you need more help, post back. Regards, Fred "Me2020" <Me2020@discussions.microsoft.com> wrote in message news:A6B20D94-EBC2-49E6-9E4F-127...

VBA date question
Why isn't this working? I have a form which has a text box for an attribute of type DATE. This attribute, foo, is normally null when the form is loaded. I tried setting the default value for the text box to "Date()" but it doesn't show up (i'm thinking it's because I'm actually running a join query to generate the record for the form so the form never gets the opportunity to display the default value for foo since it thinks it's supposed to be null, the result from the query) So I added some code like this: Private Sub Form_Open(Cancel As Integer) If (I...

create a report using vba to select the names for the report
Hi, I need to create a report of selected Customers, I have gone as far as creating a string with customer names in it. Whats next? sample = Selected_Customer_Names= [ABC], [test], [New], [A New One] ...... and so on. Is this correct for the report and/or how do i open the report with the above only listed? -- Message posted via http://www.accessmonster.com On Wed, 28 Apr 2010 03:47:34 GMT, "trevorC via AccessMonster.com" <u44860@uwe> wrote: >Hi, >I need to create a report of selected Customers, I have gone as far as >creating a string with ...

passing non-field value into vba
I need to pass the line item sequence number (lnitmseq) from the sales item detail entry window into vba. This isnt a visible field in the window, so i cannot "add field to vba" using the TOOLS --> customize toolbar window. Anyone have any idea how this can be done? Using the Modifier you can make the field visible, add it to VBA and then remove the modified window or make the field invisible again. While in the Window Layout mode, make sure that the Invisible fields are shown (Layout >> Show Invisible Fields) and then change the Visual Property, Visible = true and mov...

Hide Quck Parts in Word 2007
Hi, Is it possible to hide empty quick parts in word 2007? I am populating quick parts from a sharepoint list (wss 3.0) and some of the fields in this list are not rquired and the field names are showing when the metadata is empty. http://www.moss2007.be/blogs/vandest/archive/2009/12/03/configure-word-2007-content-controls-with-empty-placeholder-text.aspx ...

When printing, how do I keep a letter-sized document from expandi.
I have set up a landscape, letter-sized document in MS Pbulisher. But every time I try and print it, it expands the document to a legal-sized doc. Please help!!! Check your printer settings inside Publisher. -- JoAnn Paules MVP Microsoft [Publisher] "godovino" <godovino@discussions.microsoft.com> wrote in message news:6AEC49BF-CBCA-4F05-932C-034B008D6472@microsoft.com... >I have set up a landscape, letter-sized document in MS Pbulisher. But >every > time I try and print it, it expands the document to a legal-sized doc. > > Please help!!! Could ...

HR Reason Code and VBA
When changing pay code rates there is a dialog that pops up allowing the user to enter an effective date and reason code. Is there a way to get to this dialog box in VBA? This particular dialog does not seem to trigger BeforeModalDialog or AfterModalDialog. TIA, Jim That's because it's not a modal dialog. You know this because there is a drop list on it and modal dialog only have Yes/No/cancel, or OK or such. It might be modal however meaning that you have to use the hotkey to add it and the fields to vba. Control F-11 and Shift - F11 I believe - check your menu before the w...

Set print width to page width in VBA
IF I set the width, e.g. ActiveWorksheet.PageSetup..FitToPagesWide = 1 It automatically makes it 1 page tall, not good on long sheets, how do I set it to scale 1 page wide and however many pages tall? -- A)bort, R)etry, I)nfluence with large hammer. I recorded a macro when I did it manually. These are the lines that I'd keep: With ActiveSheet.PageSetup .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = False End With Trevor Best wrote: > > IF I set the width, e.g. > > ActiveWorksheet.PageSetup..FitToPagesWide = 1 > > It automat...

VBA
Hi, I am currently writing a database and what i want it to do is when one particular field is filled in eg. Cylinder, then it will pick up only "cylinder" items. I have tried this code below but it doesnt seem to work. Could someone please help me. Private Sub Job_Installable_AfterUpdate() 'If Job_Installable.[Column](1) = "Cylinder" Then ' 'Forms!OrderForm.ctlSubForm.Form!Controls.NewData ' 'Forms! ' [tblJob_Consumables SubForm]![Job_Consumable Consumable ID].ControlSource = "qlkpConsumableCylinder" 'Else...

Word attachments
I am running Windows 7 and Word 2007. I want my attachments to open in Print preview not full screen reading view. I have unchecked the box in Word Options, rebooted and resent emails with attachments to myself. However, they will not open in any other mode but full screen reading view. Any suggestions welcome. You can disable Full Screen Reading view, but you cannot force documents to open in Print Preview. If you mean Print Layout view, then you need to save them in this view; see http://word.mvps.org/FAQs/General/SaveViewAndZoom.htm -- Suzanne S. Barnhill Microsoft MVP (...

View equations created in Word 2007
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: intel Greetings! I've successfully installed Office 2008 update 12.0.1 on my MacBook Pro running 10.5.2. One of the fixes that was listed in the Microsoft Knowledgebase article associated with the update was the ability to edit equations created in Word 2007 for Windows. After applying the update, I still get a warning message when opening a file created in Word 2007: "This file contains Word 2007 for Windows equations"; the document opens with placeholders (blank squares) instead of the equations. Does anyone el...

Can't open office documents from my emails until word is openned f
When I try to open a word document or excel spreadsheet that is saved as an attachement to an email, I get the message: Windows cannot find ‘c:/users/mona/appdata/local\microsoft\windows\temporary internet files\low\content.IE5\SB2EHHFL\xxx[1].xls\’ Make sure you typed the name correctly, and then try again. If I open Word or Excel before clicking on the attachement to open it, then it works. This problem only happens when using my laptop which is running Windows Vista and office 2007. I do not have any problems with this on our desktop which is running XP and office 2003. Wo...

opening an old 1992 Word document, registry error
I tried to open a document created in 1992 but instead of opening I get a message that tells me I cannot because my registry doesn't allow it -- wrb See “Information about certain file types that are blocked after you install Office 2003 Service Pack 3” at http://support.microsoft.com/?kbid=938810 -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Seabee74" <Seabee74@discussions.microsoft.com> wrote in message news:6ADC0871-2FB3-4880-9525-5EFE3C3AD3C5@microsoft.com... >I tried to open a document...

move page from one document to another
I need some "fast" help! I have never worked in Publisher before, but need to get a project done for an organization I work for. I need to take several pages from one document and paste them into another document. Both documents are already set up in Publisher. I want to basically "copy" from one document to another. HELP!! kdramirez <kdramirez@discussions.microsoft.com> wrote: >I need to take several pages from one document and paste them into another >document. Both documents are already set up in Publisher. I want to >basically "copy&qu...

Inserting word 'merge field' into Excel
I have data in Word merge fields that I need to put in an Excel table. Each Word file is exactly the same and there are a few hundred files. If I can't do this direct to a spreadsheet, can I do it through Access? ...

i cant find my email documents
After installing an antivirus to my xp computer i cannot find all my past email. it gives a socket error number 10060 and an error number of 0x800CCC0E Please help "bAyai" <anonymous@discussions.microsoft.com> wrote in message news:b3e101c4373f$9fc2fd40$a501280a@phx.gbl... > After installing an antivirus to my xp computer i cannot > find all my past email. it gives a socket error number > 10060 and an error number of 0x800CCC0E > Please help If you uninstall it, does the error go away? ...

This document does not exist for this customer or type.
If I go to Transactions->Sales->Apply Sales Documents and bring up a customer account and a specific document number, I see a few documents that that have been applied to this document. However, the original amt and the applied amt are way off for this customer. So when I do a detail historical aged trial balance I see all these document numbers that if applied to this credit would make the original amt and applied amt equal. But they are not available in the Transactions->Sales->Apply Sales Documents list. I went into the database and saw that the items not applied to t...

Sending Word attachments to AOL and/or Mac users
When I send an email from my Outlook to people who use aol and to people who use a Mac, they can't open the .doc Word or .xls Excel attachments. They get only a .dat file which they can't open. What do I need to do as the sender so they can open/read the attachments? rebecca wrote: > When I send an email from my Outlook to people who use aol > and to people who use a Mac, they can't open the .doc Word > or .xls Excel attachments. They get only a .dat file > which they can't open. What do I need to do as the sender > so they can open/read the attachment...