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

Using Word SaveAs to a password protected document

Status
Not open for further replies.

StewartUK

Programmer
Feb 19, 2001
860
GB
A utility creates a password protected Word document using SaveAs.

Here is the line I have:
Code:
.SaveAs([I:\NewFred\Statistics\HouseKeeping.doc], _wdFormatDocument, .T., [ex0du5]))
However Word doesn't seem to recognise that I am passing it a password and it pops up, the button on the taskbar is constantly flashing and the routine fails.

I guess I could delete the file first, but is there a way of doing this with Automation?

Thanks,

Stewart
 
Stewart

I have used this with success. VFP9 and Word 2003. I'm not sure about your _wdFormatDocument . Is it defined as being 0? The correct name for the parameter is wdFormatDocument, but as long as the parameter you are using is set to 0.
Code:
#DEFINE wdFormatDocument	0	
oWord = createobject("word.application")
oDoc = oWord.documents.Add()
oDoc.SaveAS('c:\myDoc.doc',wdFormatDocument,'Hello')
oWord.Quit

And the next time I open the document, it first asks for the password.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks for your reply Mike,

Yes, _wdFormatDocument is 0.

I too have no problem with saving a new Word document with a password. The problem arises when I try to overwrite the file with the password.

What's happening is that this document is created each morning - a routine selects various bits of data and creates a Word doc using automation.

I then want to save the created Word document, overwriting the one that was created the previous morning, and it's when the program tries to do this that the problem occurs.

Stewart
 

You may want to try set your password while in the document rather than at the time of saving it.
Code:
oWord.ActiveDocument.Password ='mypassword'

And use the save function, instead of the SaveAs.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top