vb code to protect excel worksheet

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
LVL 2
leekfAsked:
Who is Participating?
 
Ryan ChongConnect With a Mentor Commented:
Try like:

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

?
0
 
Ryan ChongCommented:
objExcel.sheets(1).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

?
0
 
leekfAuthor Commented:
thanks

but i cannot set the password to protect

Could you tell me how to do that?
0
All Courses

From novice to tech pro — start learning today.