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

Password Protect Word Document in VB6

Status
Not open for further replies.

mark1110

Programmer
Joined
Apr 20, 2005
Messages
85
Location
US
Hi,

I have a VB6 application that creates a mail merge document in Microsoft Word 2003. What I would like to do is either after the mail merge process is complete, password protect the document so no one can edit it or password protect the document before the mail merge, open the word document, enter the password so I can perform the mail merge then make sure that no one can edit the document.

Here is my code to open the document:
wrdDoc.MailMerge.OpenDataSource name:=App.Path & "\" & CurrentUser$ & "\mailmerge.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source= App.Path & '\' & CurrentUser$ & '\mailmerge.xls';Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password=""""", _
SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:=wdMergeSubTypeAccess

I tried entering a password in the passworddocument, passwordtemplate, writepassword, and writepasswordtemplage field but I keep getting a cannot open document because it is password protected. I also tried using wrdDoc.Password = "hello" but I get the same error.

Can this be done?

Thanks


Mark


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top