Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use VB to open/close password protected document 1

Status
Not open for further replies.

KYWONG

MIS
Apr 6, 2004
11
HK
Hi,

I need to remove all the password for a large number of word documents. I already have a table with the document names and password. How do I code in VB to do this?

Many thanks in advance.

Kar Yan
 


Hi,

Turn on your macro recorder and record doing it.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,

I don't quite understand how the macro recorder would solve my problem. Firstly the list of documents I have is not small and the password for each document is not the same. I have a table contain the word document names and its password. I am hoping to write a small VB code base on this table to remove all the password. Can this be done?
 
What Skip suggested is good. Essentially, you only have to record about 3 or 4 documents (if that) because I don't know your level of knowledge...but at least 2 for sure.


After you record the process like:
Start Recording
OPEN document,
click unProtect,
type in pswd,
Stop Recording


You should either print out the macro code or write it out. Compare all 3/4 printouts/hand written notes for similarities. This will give you the baseline code you'll need. After that just plug-in some variable to take care of the "document name" and "password".

It's really not too hard and Skip's suggestion is on the money.

The only way it may be difficult is if the 'database' of Names & Passwords are in a flatfile or text file...and not in (let's say) Excel or Access. If that's the case then you'll have to convert it for easier document interaction.

--Miggyd

My mind not only wanders, it sometimes leaves completely.
 
Dear all,

Thanks. Now I understand the means for the recording is to examine the actual code being used. I am using VB (within Access) to perform this little function. The problem is now solved. I here share my small piece of VB code for someone else to reference...

DocL.Open "DocList", MyDB, adOpenKeyset, adLockOptimistic
DocL.MoveFirst
Set appWord = New Word.Application

Do Until DocL.EOF
SrcF = SrcLoc & DocL!docname & ".doc"
FinalF = DestLoc & DocL!docname & ".doc"
DocPassword = DocL!docpasswd
Set wrdDoc = appWord.Documents.Open(FileName:=DestF, PasswordDocument:=DocPassword)
With ActiveDocument
.Password = ""
.WritePassword = ""
End With
ActiveDocument.SaveAs FileName:=FinalF
wrdDoc.Close
DocL.MoveNext
Loop
DocL.Close
 
1) Congradulations on getting it to work.

2) Thanks for sharing. I'm sure someone someday will use your info and modify it for their means.

3) You're welcome for the elaboration.

As a side note:
You should create a module and call it something like Utilities or CodeSnips and copy this AND any other codes you create to it. THEN! add comments on the code so that you can later look back at it and say "Oh Yeah, that's what I used it for...maybe it'll work (w/some modifications) in the code I'm now writing!"


I have programs dating back to 1984 and I can tell you if I hadn't commented them I honestly wouldn't remember what they did or why I made them in the first place...it truely a big BIG help.

--MiggyD

My mind not only wanders, it sometimes leaves completely.
 



I have programs dating back to 1984...
and we all know what happened in Ninteen Eighty Four!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Actually a lot of people probably don't know. I turned 27. Apple introduced Macintosh. George Orwell's book was a few years off. I am sure there were other things, it has been a few years.
 
To Skip:

Yes we all know...Welles wrote about my world.

See in my alternate earth I wrote a program that made time travle possible. Yes, yes, in 1984. So I went back in time and talked with Mr. Welles while he was a young'n and told him of all the wonderful stuff he'll see...and came back.

To my suprise, he pawned it off as his own work. I got no royalties! And to make matters worse, I ended up in your earth instead of my own.

There are subtle differences like not having to completely stop at a STOP sign...but this world's got TT and that makes all the bad stuff go away. [wink]

--MiggyD

My mind not only wanders, it sometimes leaves completely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top