troubleshooting Question

protect and unprotect excel sheet

Avatar of al4629740
al4629740Flag for United States of America asked on
Visual Basic ClassicMicrosoft Excel
1 Comment1 Solution2029 ViewsLast Modified:
I have a protected excel sheet. However I need to unprotect it from vb6 and then after I add the data to it, I need to protect afterwards.  I have a password also.  How can I do this?

I have attached a secton of my code relating to what I am asking?


Set ApExcel = CreateObject("Excel.application") 'Creates an object
ApExcel.Visible = True ' So you can see Excel
 
'ApExcel.Workbooks.Open "\\2000server\t4e\Attendance Sheet.xls"
ApExcel.Workbooks.Open "C:\Attendance Sheet.xls"
 
rec.MoveFirst
 
For k = 1 To 200
 
 
    Call CopySheet(ApExcel, "SheetBlank", "Sheet" & k)
 
    
    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(4, 5).Formula = Org & " - Youth"
    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(6, 14).Formula = Format(Now, "mmmm")
    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(6, 33).Formula = Year(Date)
                   
       
        
                    
                For i = 11 To 30
                
                If IsNull(rec.Fields(0)) Then
                rec.Fields(0) = ""
                Com(7) = StrConv(rec.Fields(0), vbProperCase)
                Else
                Com(7) = StrConv(rec.Fields(0), vbProperCase)
                End If
                
                If IsNull(rec.Fields(1)) Then
                rec.Fields(1) = ""
                Com(8) = StrConv(rec.Fields(1), vbProperCase)
                Else
                Com(8) = StrConv(rec.Fields(1), vbProperCase)
                End If
                
                
                If Com(8) = "" Then
                    If Format(rec.Fields(4), "yyyymm") = Format(Now, "yyyymm") Then
                    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(i, 1).Formula = Com(7) & " * "
                    Else
                    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(i, 1).Formula = Com(7)
                    End If
                End If
                
                If Not Com(8) = "" Then
                    If Format(rec.Fields(4), "yyyymm") = Format(Now, "yyyymm") Then
                    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(i, 1).Formula = Com(7) & ", " & Com(8) & " * "
                    Else
                    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("Sheet" & k).Cells(i, 1).Formula = Com(7) & ", " & Com(8)
                    End If
                End If
                         
                         rec.MoveNext
                    
                    If rec.EOF = True Then
                    rec.Close
                    ApExcel.DisplayAlerts = False
                    ApExcel.Workbooks("Attendance Sheet.xls").Sheets("SheetBlank").Delete
                    ApExcel.DisplayAlerts = True
                    GoTo Procedure2
                    End If
                    
                Next i
        
 
Next k
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros