Solved

vb code to protect excel worksheet

Posted on 2004-08-04
3
618 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 50

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 50

Accepted Solution

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

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

?
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 70
How does CurrentUser work? 10 37
Passing a Text Box name to a Sub 6 96
How to read File Date Created using VB6 8 39
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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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