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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save word document with password through VB 1

Status
Not open for further replies.

isha

MIS
Mar 7, 2002
216
IN
I have developed a package in VB through which some word documents are added and saved in a folder. These word documents are opened again when needed through the Package.
I want that these word documents are saved with a password. How can I do it through VB. And how to give the password at the time of opening the document.

Please help.
Thanks.
 
Use the Word VB Help. If you have referenced the Word Object Library in your project then Word VB help is available dircetly from your project.

The relevant entry says:
This example opens Earnings.doc, sets a password for it, and then closes the document.

Set myDoc = Documents _
.Open(FileName:="C:\My Documents\Earnings.doc")
myDoc.Password = "why"
myDoc.Close



________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Johnwm
Thanks for your reply.

i am adding a word document with the following code.

Dim wrd As Word.Application
Set wrd = CreateObject("word.Application")
wrd.Application.Visible = True
wrd.Documents.Add
wrd.ActiveDocument.SaveAs Trim(Text5.Text) & Trim(Text6.Text) & ".doc"

Can i give the password with SaveAs?

I am opening the document with the following code.

wrd.Documents.Open Text5.Text

If the document has a password, how can I give it with the above code at the time of opening the document?
 
Did you try:
wrd.ActiveDocument.Password = "password"
immediately before doing the 'saveas'


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Johnwm,
Thanks for the suggestion. The word document is saved with the password using the code.
wrd.ActiveDocument.Password = "password"

But the problem of reopening the above document still remains. How to give the password with the following code so that we don't have to give the password manually. I want to include it in the code so that the document opens immediately.

wrd.Documents.Open Text5.Text



 
Johnwm
The opening problem has been solved using
wrd.Documents.Open Text5.Text, , , , "password"
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top