Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

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
0
leekf
Asked:
leekf
  • 2
1 Solution
 
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
 
Ryan ChongCommented:
Try like:

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

?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now