Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
explain this one to me.... Dave F Excel Discussion (Misc queries) 10 November 16th 06 11:05 PM
VBA code not working- repost to further explain problem [email protected] Excel Programming 8 August 29th 06 09:15 PM
Please Explain Two Lines of Code ca1358 Excel Programming 1 January 18th 06 04:47 PM
Can someone explain this code to me dht[_2_] Excel Programming 1 September 13th 04 12:03 PM
Please explain why following code doesn't work.... FMNT80 Excel Programming 2 July 23rd 03 06:07 PM


All times are GMT +1. The time now is 08:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"