Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Protect sheets via VB6 automation

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").Protec t Password:=pwdF,
Drawings:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
oXl.Workbooks(nomeWbk).Sheets("Other_Sheet").Prote ct Password:=pwdF,
Drawings:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
oXl.Workbooks("Calc_Sheet.xls").Close SaveChanges:=True

oXl.Quit
Set oXl = Nothing

------------------------------------------------------------------------------------------------------


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Protect sheets via VB6 automation


Hello Maurizio,

Your code looks fine. You say you have to Disable Macros to run the
code. If macros are disabled your code (a macro) won't run. If the
code doesn't execute, you will not be able to password protect the
worksheets.

You can trry a couple of things. Either set your security to low, which
will any macro to run (a dangerous option) or self sign the macro which
will allow it to run because it is now recognized by Windows as safe.
If you are planning to use your code on a network you may require
additional permissions from your administrator.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=556247

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Protect sheets via VB6 automation

Thank you, I have some doubts.
How works macro signing ?
If I apply a certificate to a template file (xlt), each sheet based on that
template inherits signing ?
Do you have any idea of costs of signing ?

Maurizio Bellantone

"Leith Ross" ha
scritto nel messaggio
...

Hello Maurizio,

Your code looks fine. You say you have to Disable Macros to run the
code. If macros are disabled your code (a macro) won't run. If the
code doesn't execute, you will not be able to password protect the
worksheets.

You can trry a couple of things. Either set your security to low, which
will any macro to run (a dangerous option) or self sign the macro which
will allow it to run because it is now recognized by Windows as safe.
If you are planning to use your code on a network you may require
additional permissions from your administrator.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:
http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=556247



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect sheets in one go mohavv Excel Discussion (Misc queries) 4 March 11th 08 10:21 PM
how do i password protect an .xls file? how do i unlock it for automation. e.g. want to unlock and access a .xls from another .xls macro. Daniel Excel Worksheet Functions 1 June 24th 05 02:59 PM
Protect all Sheets Phil Osman Excel Discussion (Misc queries) 0 June 17th 05 01:55 AM
Protect sheets David Excel Programming 6 June 9th 05 07:56 AM
how to protect sheets from VBA? jon Excel Programming 1 September 16th 04 06:11 PM


All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"