PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 2024 → WD: Protect an Excel file with Passord
WD: Protect an Excel file with Passord
Started by Gianni Spano, Oct., 21 2010 7:43 PM - 2 replies
Posted on October, 21 2010 - 7:43 PM
Hello
I have over 120 excel files to protect with the same password.
These files are created with WD, reading each record (one for every excel file)
from a customer file and because the context of each file is private, i need to secure these files with a password. Every time a user try to open a file, it must prompt to input a known password.
Does someone have a solution to set a password during the step
when i generate the excel file?
Below there is a little solution i have found in Visual Basic:
Sub ProtectFile()
Dim nombre As Integer
nombre = ActiveWorkbook.Sheets.Count
Application.ScreenUpdating = False
For i = 1 To nombre
Worksheets(i).Protect , password:="blabla"
Next i
End Sub
Sub UnProtetFile()
' unprotect all sheets
Dim nombre As Integer
nombre = ActiveWorkbook.Sheets.Count
Application.ScreenUpdating = False
For i = 1 To nombre
Worksheets(i).Unprotect , password:="blabla"
Next i

TIA
Gianni
Posted on October, 22 2010 - 1:58 AM
I didn't test it but this code and your explanation don't seems to match.
NOTE: the code that I am suggesting is untested. I don't have access to WinDev, i'm at home (today at least i leave the office at a decent hour).
to translate this code to Wlanguage use something like this:
m_xExcel is object OLE dynamic
m_xExcel=new object OLE "Excel.Application"
m_xExcel>>Workbooks>>Open("c:\myfiles\test.xls")
wint is int
wi is int
wint = m_xExcel>>ActiveWorkbook>>Sheets>>Count
FOR wi = 1 TO wint
m_xExcel>>Sheets( wi)>>Protect("aaa")
END
m_xExcel>>ActiveWorkbook>>Saveas("c:\myfiles\test_1.xls")
m_xExcel>>ActiveWorkbook>>close(False)
m_xExcel>>Quit()
delete m_xExcel
to do what you are asking use something like this:
m_xExcel is object OLE dynamic
m_xExcel=new object OLE "Excel.Application"
m_xExcel>>Workbooks>>Open("c:\myfiles\test.xls")
m_xExcel>>ActiveWorkbook>>Saveas("c:\myfiles\test_1.xls",*,"aaa")
m_xExcel>>ActiveWorkbook>>close(False)
m_xExcel>>Quit()
delete m_xExcel
Posted on October, 22 2010 - 9:28 AM
Thanks Paulo
I will try your solution tomorrow morning..
Thanks again for your support..
:spos:
Gianni