Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Would someone explain what this code does?
Would someone explain what this line of code does? If InStr(oWin.Caption, "(") 0 Then oWin.Close Why does it looke for "("? Here is the whole story. I would like to programmatically protect the VBProject of a worksheet which is programmatically added. I have a .xla file that adds a workbook (book1) with one sheet and add codes to the sheet's worksheet_selectionchange event. I found the following code on the Internet which is supposed to protect a worksheet's VBProject. But no matter what I do, it is the xla's VBProject that is protected, not the sheet1's VBProject. I guess the code windows are not properly closed. But I cannot read the code. Hence, I have no idea how to modify it. Thanks. Public myBook as workbook Application.SheetsInNewWorkbook = 1 Set myBook = Application.Workbooks.Add .................................... .................................... call PVBP(myBook, "test") Sub PVBP(WB As Workbook, ByVal Password As String) Dim VBP As VBProject, oWin As VBIDE.Window Dim wbActive As Workbook Dim i As Integer Set VBP = WB.VBProject Set wbActive = ActiveWorkbook ' Close any code windows To ensure we hit the right project For Each oWin In VBP.VBE.Windows If InStr(oWin.Caption, "(") 0 Then oWin.Close Next oWin WB.Activate ' now use lovely SendKeys To unprotect Application.OnKey "%{F11}" SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & Password & "~" Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute ' WB.Save End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
explain this one to me.... | Excel Discussion (Misc queries) | |||
VBA code not working- repost to further explain problem | Excel Programming | |||
Please Explain Two Lines of Code | Excel Programming | |||
Can someone explain this code to me | Excel Programming | |||
Please explain why following code doesn't work.... | Excel Programming |