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

Working with Excel thru Fox Pro code, PASSWORD

Status
Not open for further replies.

johnod33

Programmer
Mar 17, 2003
34
US
Sometimes I add a passwrod to an Excel table created in my Fox Pro code using these lines of code.

WITH oExcel
.
.
.(some code removed)
.
.ActiveWorkbook.Password = "XXX"
.ActiveWindow.CLOSE(xlSaveChanges)
.APPLICATION.QUIT
ENDWITH

I want to use a password to protect the spreadsheet from being modified not being opened. I usually just record a macro and copy the code into Fox Pro and then try and figure out what needs to be changed from the copied VB code to make it work with Fox Pro. I am having lots of trouble with this one. I don't get and syntax errors anymore and the code runs but it just doesn't work. It does add a write protect password to the table.

This is where I am at:

.ActiveWorkbook.WritePassword = "XXX"
.ActiveWorkbook.ReadOnlyRecommended = True

(VB code for write password WriteResPassword, I took out the RES and it worked for Fox Pro)

Any suggestions?

John O'D

Here is the entire program so far:

#DEFINE True .T.
#DEFINE False .F.
#DEFINE xlSaveChanges 2

oExcel = CREATEOBJECT ("Excel.Application")
oExcel.VISIBLE = .T.

WITH oExcel
.DisplayAlerts = .F.
.Workbooks.OPEN ("Open my file.xls")
.ActiveWorkbook.WritePassword = "XXX"
.ActiveWorkbook.ReadOnlyRecommended = True
.ActiveWindow.CLOSE(xlSaveChanges)
.APPLICATION.QUIT
ENDWITH
 
Sorry it should say it DOESN'T add a passowrd.

John O'D
 
This works, note extra password line added:

#DEFINE True .T.
#DEFINE False .F.
#DEFINE xlSaveChanges 2

oExcel = CREATEOBJECT ("Excel.Application")
oExcel.VISIBLE = .t.

WITH oExcel
.DisplayAlerts = .F.
.Workbooks.OPEN ("c:\test-password.xls")

*Extra line here
.ActiveWorkbook.Password = "XXX"

.ActiveWorkbook.WritePassword = "XXX"
.ActiveWorkbook.ReadOnlyRecommended = True
.ActiveWindow.CLOSE(xlSaveChanges)
.APPLICATION.QUIT
ENDWITH

Regards
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top