RE: Remove Password
- From: matt <matt@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Jul 2008 14:00:07 -0700
Many Thanks Gordon,
After hours and hours and hours, I finally got what I needed. And it was SO
simple. I think I maybe had a typo or something or the wrong order of
something but this was all I needed:
ActiveDocument.SaveAs FileName:="temp_document2.doc", Password:="", _
WritePassword:="", ReadonlyRecommended:=False
I want to thank you for taking the time to look into this.
Thanks again,
Matt
"Gordon Bentley-Mix" wrote:
My apologies Matt. I got a bit confused between protection (forms, read-only,.
etc.) and "password to open / modify" security. However, I've done some
rather extensive investigation, and I think I know what the problem is now.
You're getting prompted for the password to _open_ the document
"Temp_Doc.doc" when you try to save it, correct? What I think is happening is
that this document already exists - and in a version that has "password to
open" protection on it - and Word is trying to open this existing document
before saving the new document over it. I bet that if you delete the existing
"Temp_Doc.doc" between runs, you don't get prompted for the password. (I know
you can't test this now, but give it a go tomorrow.)
There are a couple of possible solutions to this problem, and being a bit of
a "belt-n-braces" man myself, I'd probably implement both of them just to be
sure.
First, just BEFORE you do your SaveAs, include the line:
ActiveDocument.Password = ""
This will remove the "password to open" protection from the document before
you save it as "Temp_Doc.doc", but it should leave the original document
intact. And with no "password to open" protection on the newly-created, you
shouldn't get prompted for the password in any subsequent runs.
Second, I'd look into writing some code to delete the "Temp_Doc.doc" after
you've sent it off. Investigate the "Kill" statement in VBA. Here is a bit of
code from one of my templates that contains similar functionality to help get
you started:
Private Sub cmdEMail_Click()
Dim MyOlapp As Object, MyItem As Object, MyAttachment As Object, MyFile
As Variant, olMailItem
On Error Resume Next
UserForm1.Hide
MyFile = Environ("Temp") & "\Kewl.doc"
ActiveDocument.SaveAs MyFile
Set MyOlapp = CreateObject("Outlook.Application")
Set MyItem = MyOlapp.CreateItem(olMailItem)
Set MyAttachment = MyItem.Attachments
MyItem.Subject = "Kewl Document Attached"
MyAttachment.Add MyFile
Documents(MyFile).Close (wdDoNotSaveChanges)
Kill MyFile
MyItem.Display
Unload UserForm1
End Sub
Note that this is very old code that I inherited from someone else so it's
probably not the most elegant example, but you should get the idea.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
"matt" wrote:
Hey Gordon thanks for the reply,
I won't be able to test this till I get to work tomorrow, but you know what
your absolutley right. I guess I never thought of it like that, about trying
to remove the protection and then the saveAs. I guess I just didn't have the
right order of commands
Using Word 2003 - I can't look at it now cause I have Office 2007 at home.
Is unprotect the same thing as assigning a password, because I'm pretty sure
I go to Tools/Options --> Security tab, and then I asigned a password in the
second textbox. But I think there is a button that says Protect or Protection
or something like that, and when you click it, it opens another box that
gives you some options to protect your document. And I'm positive I didn't
select anything in there, all I did was asign a password.
So will the "ActiveDocument.Unprotect" command be what I want to use?
I'll let you know tomorrow when I get to work what happens.
Thanks again,
Matt
"Gordon Bentley-Mix" wrote:
Some rough-n-ready sample code to show you what I mean. Note the order of
execution.
Private Sub EmailMe()
With ActiveDocument
If .ProtectionType <> wdNoProtection Then .Unprotect "myPassword"
.SaveAs "Temp_Doc.doc"
'Do the other stuff to the document to clean it up & email it
End With
End Sub
Protection is removed from the ActiveDocument and then the ActiveDocument is
saved with a new file name, leaving the original document intact - including
the protection.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
"matt" wrote:
Hello,
I have a document that is protected by a password. And I have a macro that
sends the document in an email. But I have some other stuff in that macro
that removes some things before it sends it.
Before it removes the those things, I have it execute a:
ActiveDocument.SaveAs "Temp_Doc.doc"
And then after it executes the "SaveAs" it prompts me for the password again
within the new file "Temp_Doc.doc". How do I remove the password protection
while its saving or after it's saved programmatically, while still keeping it
in the origional document? Been trying to do this for HOURS!!!
Please Help!
Thanks
- References:
- RE: Remove Password
- From: Gordon Bentley-Mix
- RE: Remove Password
- From: matt
- RE: Remove Password
- From: Gordon Bentley-Mix
- RE: Remove Password
- Prev by Date: Re: VBA equivalent of encodeURI
- Next by Date: Re: Dealing with Tables in VBA
- Previous by thread: RE: Remove Password
- Next by thread: Re: Remove Password
- Index(es):