Solved

vb code to protect excel worksheet

Posted on 2004-08-04
3
619 Views
Last Modified: 2008-01-09
how to protect excel work sheet with visual basic?

the macro code of protection is:
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

how to transform it to visual basic code?

PS: I open excel with the following code:

    Set objExcel = GetObject(Source)
    objExcel.Application.Visible = True
    objExcel.windows(1).Visible = True
    objExcel.sheets(1).cells(1, 1).Value = "hihi"

........ after that I want to protect the workbook



Thanks
0
Comment
Question by:leekf
  • 2
3 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 11723266
objExcel.sheets(1).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

?
0
 
LVL 2

Author Comment

by:leekf
ID: 11723465
thanks

but i cannot set the password to protect

Could you tell me how to do that?
0
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 11723598
Try like:

objExcel.sheets(1).Protect Password:=YourPassword

?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question