PDA

View Full Version : Solved: calling a sub in another add-in



makako
04-13-2007, 07:55 AM
recently i found an addin called password. one has to take sheet by sheet and hit on a menu button. I already looked for the asigned macro and its called unprotectsheet, what i need to do is to un protect several sheets in a workbook. I tried

for each xsheet in workbook.sheets
xsheet.select
unprotectsheet
next

but unprotectsheet must be a private sub and i cannot use it from my module. Is there any way i can call this sub form my macros? thanks

Bob Phillips
04-13-2007, 08:16 AM
Set a reference to the addin and try calling it directly.

makako
04-13-2007, 08:25 AM
sorry, i do not know how to do that

Bob Phillips
04-13-2007, 08:47 AM
Go to the VBIDE, Alt-F11

Go to Tools>References, and find the addin within that list, and check it

Then try your code again. Not guaranteed if the procedure is not exposed, but my bet is that it is.

Bob Phillips
04-13-2007, 09:00 AM
You could also try writing your own version



Sub UnprotectSheets()
Dim sh As Object
Dim arySheets
Dim i As Long
ReDim arySheets(0 To ActiveWindow.SelectedSheets.Count - 1)
For Each sh In ActiveWindow.SelectedSheets
If TypeName(sh) = "Worksheet" Then
Set arySheets(i) = sh
i = i + 1
End If
Next sh
For i = 0 To UBound(arySheets)
arySheets(i).Unprotect
Next i
End Sub


This will work on the selected sheets, one or many, contiguous or not.

makako
04-13-2007, 09:58 AM
thanks, setting the reference solveded it. regarding doing it myself it cannot be done, i dont have the password. :)

lucas
04-13-2007, 10:02 AM
Bob just gave you the code to do it without the addin.....use it in your workbook instead of using the addin....

Bob Phillips
04-13-2007, 10:49 AM
Are you saying that this add-in cracks passwords? Shame on you.