WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determine Workbook or WorkSheet Protection


;///////////////////////////////////////////////
;Winbatch 2005C - Excel
;
;Determine Workbook or WorkSheet Protection
;[modify as needed]
;
;Stan Littlefield - September 13, 2005
;///////////////////////////////////////////////

#DefineSubRoutine isProtected(n,oOBJ,sName) ;send sname as "" for workbook only
isP = @FALSE
If n==1
   isP=oOBJ.ProtectWindows
   isP=oOBJ.ProtectStructure
   If isP
      Display(2,"WorkBook Protection","IS Protected")
   Else
      Display(2,"WorkBook Protection","IS NOT Protected")
   EndIf
Else
   isP=oOBJ.ProtectContents
   isP=oOBJ.ProtectDrawingObjects
   isP=oOBJ.ProtectScenarios
   If isP
      Display(2,"WorkSheet %sname% Protection","IS Protected")
   Else
      Display(2,"WorkSheet %sname% Protection","IS NOT Protected")
   EndIf
EndIf
Return(isP)
#EndSubRoutine


types="Excel Workbooks|*.xls|"
cXLS=AskFilename("Choose File To Detect Protection", DirScript(), types, "", 1)
If ! FileExist(cXLS) Then Exit

oXL = CreateObject("Excel.Application")
If oXL == 0 Then Exit
oXL.Visible          = 1
oXL.ScreenUpdating   = 1
oXL.UserControl      = 1
oXL.DisplayAlerts    = 0
oXL.WorkBooks.Open(cXLS)
isProtected(1,oXL.ActiveWorkbook,"")


nSheets = oXL.ActiveWorkbook.Sheets.Count

For i = 1 To nSheets
   oWS=oXL.ActiveWorkbook.Worksheets(1)
   oWS.Activate()
   isProtected(2,oWS,oWS.Name)
Next

oXL.Quit()
oXL=0

Article ID:   W17150
File Created: 2007:07:03:14:28:30
Last Updated: 2007:07:03:14:28:30