View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Excel prompts for VBA password when opening

The code may be breaking due to an error that only occurs in the users
setup. Looking at yours it is prone to all sorts of errors, eg
user's security settings do not allow access to VB Project.
the workbook already has the reference
the addin is not in the expected location

Sub AddSolver()
Dim strSolverPath As String
Dim wbSolver As Workbook
Dim objRef As Object
Dim oWB As Object ' NOT as workbook
Dim ad As AddIn

On errror GoTo errH
Set oWB = ActiveWorkbook

With Application.AddIns("Solver Add-In")

strSolverPath = .FullName
On Error Resume Next
Set wbSolver = Workbooks(.Name)
On Error GoTo errH

If wbSolver Is Nothing Then
.Installed = True
End If
End With

On Error Resume Next
Set objRef = oWB.VBProject.References("SOLVER")
On errro GoTo errH
If objRef Is Nothing Then
oWB.VBProject.References.AddFromFile strSolverPath
End If

Exit Sub
errH:
MsgBox Err.Description, , "Error in AddSolver"
End Sub

Of course there might be some other error.

Regards,
Peter T


"OMER" wrote in message
...
Hola,
I have a workbook in which I protected the VBA code with a password. It
works fine. The user doesn't have access to the code. I'm automatically
setting the Solver referece using the following code (partly shown).

Set oWB = ActiveWorkbook
strSolverPath = Application.LibraryPath & "\SOLVER\SOLVER.XLAM"
With AddIns("Solver Add-In")
.Installed = False
.Installed = True
End With
oWB.VBProject.References.AddFromFile strSolverPath


The situation is that when the user opens the workbook it's being asked
for
the VBA Project password. The user clicks Cancel and continue without the
need to know the password.

Is there a way to prevent the code to prompt for password?
(I want to keep the code password protected).

Thank you for your help