Removing Password From Document Fails

S

scorpion53061

I realize this is a vba group but I am wondering if anyone might have
an idea what might be happening here. I create the instance of word,
open the document i want to remove the password from, set it so there
is no password, close it and reopen only to find the password prompt
again.

Any ideas?

Dim Word As Object = CreateObject("Word.Application")
Word.Visible = True
'Word.DisplayAlerts = 0
Word.Documents.Open(filename:=Application.StartupPath &
filename, PasswordDocument:="test")

Word.Application.Activate()

With Word.Application.ActiveDocument
.ReadOnlyRecommended = False
.EmbedTrueTypeFonts = False
.SaveFormsData = False
.SaveSubsetFonts = False
.Password = ""
.WritePassword = ""
.OptimizeForWord97 = False
End With

Word.Application.ActiveDocument.Save()
Word.Application.ActiveDocument.Close()
Word.Application.Quit()

Me.AxFramerControl1.Open(Application.StartupPath &
filename)
'password still being asked for
 
G

Graham Mayor

In Word vba, the following works

Dim OpenPass As String
Dim WritePass As String
OpenPass = "password1"
WritePass = "password2"
Documents.Open FileName:="Passworded.doc", _
PasswordDocument:=OpenPass, _
WritePasswordDocument:=WritePass
With ActiveDocument
.Password = ""
.WritePassword = ""
End With
ActiveDocument.Close wdSaveChanges
Documents.Open FileName:="Passworded.doc" 'unprotected

and

Dim OpenPass As String
Dim WritePass As String
OpenPass = "password1"
WritePass = "password2"
Documents.Open FileName:="Passworded.doc"
With ActiveDocument
.Password = OpenPass
.WritePassword = WritePass
End With
ActiveDocument.Close wdSaveChanges
Documents.Open FileName:="Passworded.doc", _
PasswordDocument:=OpenPass, _
WritePasswordDocument:=WritePass

will reprotect it?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

scorpion53061

In Word vba, the following works

Dim OpenPass As String
Dim WritePass As String
OpenPass = "password1"
WritePass = "password2"
    Documents.Open FileName:="Passworded.doc", _
    PasswordDocument:=OpenPass, _
    WritePasswordDocument:=WritePass
    With ActiveDocument
        .Password = ""
        .WritePassword = ""
    End With
    ActiveDocument.Close wdSaveChanges
    Documents.Open FileName:="Passworded.doc" 'unprotected

and

Dim OpenPass As String
Dim WritePass As String
OpenPass = "password1"
WritePass = "password2"
    Documents.Open FileName:="Passworded.doc"
    With ActiveDocument
        .Password = OpenPass
        .WritePassword = WritePass
    End With
    ActiveDocument.Close wdSaveChanges
    Documents.Open FileName:="Passworded.doc", _
    PasswordDocument:=OpenPass, _
    WritePasswordDocument:=WritePass

will reprotect it?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>










- Show quoted text -

It in fact did not. That is essentially the same thing I have. What I
do is

copy the document from a server to a local harddrive

open the local hard drive copy sending the password. It opens fine. I
send the code to remove the password. I save the document and its
changes.

I then move to open teh document again. However unfortuantely it does
not seem to have had the password removed. If however I slow it down
and step through the code it DOES work. Just quite odd.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top