M
Maurizio BELLANTONE
Hi,
I try to use code below in order to protect sheets with a password to an
example file I want to add to an application.
When code run, because in the example file there are some macros, appear the
macro security warning: I must choose 'Disable Macros' but password is not
set.
There is somthing wrong in my code ?
There is another method in order to set password ?
TIA,
Maurizio Bellantone
------------------------------------------------------------------------------------------------------
Dim oXl As Excel.Application, myExampleFile As String, pwdF As String,
nameWbk As String
On Error Resume Next
myExampleFile = "c:\MyApps\MyExample.xls"
FileCopy myExampleFile, RTrim(myExampleFile) & ".backup"
pwdF = EncryptedPwd()
Set oXl = GetObject(myExampleFile): ', "Excel.Application")
If Err <> 0 Then
Set oXl = CreateObject("Excel.Application")
End If
nameWbk = GetFileNameFromPath(myExampleFile) ' extract only
the filename
' there are 2 sheets in the workbook
oXl.Workbooks(nomeWbk).Sheets("Calc_Sheet").Protect Password:=pwdF,
Drawings:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
oXl.Workbooks(nomeWbk).Sheets("Other_Sheet").Protect Password:=pwdF,
Drawings:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
oXl.Workbooks("Calc_Sheet.xls").Close SaveChanges:=True
oXl.Quit
Set oXl = Nothing
------------------------------------------------------------------------------------------------------
I try to use code below in order to protect sheets with a password to an
example file I want to add to an application.
When code run, because in the example file there are some macros, appear the
macro security warning: I must choose 'Disable Macros' but password is not
set.
There is somthing wrong in my code ?
There is another method in order to set password ?
TIA,
Maurizio Bellantone
------------------------------------------------------------------------------------------------------
Dim oXl As Excel.Application, myExampleFile As String, pwdF As String,
nameWbk As String
On Error Resume Next
myExampleFile = "c:\MyApps\MyExample.xls"
FileCopy myExampleFile, RTrim(myExampleFile) & ".backup"
pwdF = EncryptedPwd()
Set oXl = GetObject(myExampleFile): ', "Excel.Application")
If Err <> 0 Then
Set oXl = CreateObject("Excel.Application")
End If
nameWbk = GetFileNameFromPath(myExampleFile) ' extract only
the filename
' there are 2 sheets in the workbook
oXl.Workbooks(nomeWbk).Sheets("Calc_Sheet").Protect Password:=pwdF,
Drawings:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
oXl.Workbooks(nomeWbk).Sheets("Other_Sheet").Protect Password:=pwdF,
Drawings:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
oXl.Workbooks("Calc_Sheet.xls").Close SaveChanges:=True
oXl.Quit
Set oXl = Nothing
------------------------------------------------------------------------------------------------------