MACRO TO SELECT A PARTICULAR SHEET!

J

jay dean

I need two macros -

1. The first macro selects among the unhidden sheets in a workbook
called "A.xls", the sheet with the tabname containing the substring h3p.

2. The second macro will protect all workbooks in a folder called
"Afold" with the password "avba".

I would appreciate any help with this.
Thanks.
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
N

Nick Hodge

Jay

The code below should get you started

1)

Sub findSheet()
Dim wks As Worksheet
For Each wks In Workbooks("A.xls").Worksheets
If InStr(1, wks.Name, "h3p") Then
wks.Activate
Exit Sub
End If
Next wks
MsgBox "No sheet with name h3p found", vbOKOnly + vbExclamation
End Sub

2)

Sub GetProtectFilesInFolder()
Dim sCurrFName As String
Dim x As Integer
With Application
.ScreenUpdating = False
.DisplayAlerts = False
sCurrFName = Dir("C:\Afold\*.xls")
Do While sCurrFName <> ""
Workbooks.Open ("C:\Afold\" & sCurrFName)
Workbooks(sCurrFName).SaveAs Filename:=sCurrFName, Password:="avba"
Workbooks(sCurrFName).Close
sCurrFName = Dir
Loop
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top