Ask Your Question

How to protect worksheet using com object [closed]

asked 2016-03-14 01:40:44 +0100

pjones1983 gravatar image

updated 2020-07-22 14:04:11 +0100

Alex Kemp gravatar image

I am looking to programmatically set the protect worksheet and set password. If anyone can give me a few pointers.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-07-22 14:04:17.918754

2 Answers

Sort by » oldest newest most voted

answered 2016-03-14 09:36:33 +0100

JohnSUN gravatar image

See subroutines ProtectSheets() and UnprotectSheets() in standard library Tools module Misc.

Methods .Protect(<password>) and .Unprotect(<password>) of object Sheet has one parameter <password> as String.

edit flag offensive delete link more

answered 2016-03-15 11:47:53 +0100

pjones1983 gravatar image

updated 2016-03-15 11:57:30 +0100

Works Perfectly. Cheers. John sun

Written In not complete code

    Dim oSM As Object = CreateObject("")
    Dim oMM As Object = oSM.createInstance("")
    Private WorkSheet As Object
    Dim OpenPar(1) As Object
    OpenPar(0) = MakePropertyValue("Hidden", True)
    Spreadsheet = oMM.LoadComponentFromUrl("file:///'Location'/" & SpreadSheetName, "_blank", 0, OpenPar)
    WorkSheet = Spreadsheet.Sheets.getByName(WorkSheetName)

       'Do something with worksheet'

     Dim arg(-1) As Object
    Spreadsheet.storetoURL("file:///'Location'/" & SaveName, arg)

 Function MakePropertyValue(cName, uValue) As Object
    Dim oPropertyValue As Object
    Dim oSM As Object
    oSM = CreateObject("")
    oPropertyValue = oSM.Bridge_GetStruct("")
    oPropertyValue.Name = cName
    oPropertyValue.Value = uValue
    MakePropertyValue = oPropertyValue
End Function
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-03-14 01:40:44 +0100

Seen: 147 times

Last updated: Mar 15 '16