G
Guest
I have found what appears to be an error in the VBA
environment running a macro under Excel 2003 on Windows
XP Professional. The same macro runs fine under Excel
2000 on Windows 2000 which I think does indicate that
this is a genuine error in the VBA environment.
I'm using the code below to check if there is a reference
to the Solver addin. If there isn't a reference, the code
adds the reference. This works fine the first time, but
gives an "already defined" error if run again. I would
expect the code to correctly determine that the reference
already exists and exit the subroutine without attempting
to define the already existing reference - and indeed
this is the case on Excel 2000 on Windows 2000 - but it
is failing on the PC running Excel 2003 and Windows XP
Professional.
Interestingly - and I think this is relevant - the
ActiveVBProject and VBProject are both shown as "VBA
Project" the first time the code is run but the
ActiveVBProject changes to "SOLVER" for subsequent calls
to the code when the error message appears.
So to produce the error on the PC running Excel 2003 and
XP Pro I uncheck the reference to Solver in the VBA
editor, quit Excel completely, start Excel by double
clicking the spreadsheet in Explorer and click the button
that calls the code. The code works fine the first time
but gives the error on subsequent calls.
Does anyone know how I go about trying to get MS to fix
this problem? I've rung local support who say that for
$50 I can speak to an MS professional who I guess woudl
verify what I'm saying and start the bug report process.
Does anyone know if this process is likely to be
fruitful? Or do MS employees monitor these newsgroups?
(And maybe I can save my $50 )
Cheers
David
Code:
Sub Button2_Click()
On Error GoTo ErrorHandler ' Enable error-handling
routine.
MsgBox Prompt:="VBProject name is " +
ThisWorkbook.VBProject.Name, Buttons:=vbCritical
MsgBox Prompt:="ActiveVBProject name is " +
Application.VBE.ActiveVBProject.Name, Buttons:=vbCritical
i = 1
Do Until ((i = AddIns.Count) Or _
(StrConv(Left(AddIns(i).Name, 6),
vbUpperCase) = "SOLVER"))
i = i + 1
Loop
If (StrConv(Left(AddIns(i).Name, 6), vbUpperCase)
= "SOLVER") Then
AddIns(i).Installed = True
j = 1
Do Until (j =
Application.VBE.ActiveVBProject.References.Count Or _
(StrConv(Left
(Application.VBE.ActiveVBProject.References(j).Name, 6),
vbUpperCase) = "SOLVER"))
j = j + 1
Loop
If (StrConv(Left
(Application.VBE.ActiveVBProject.References(j).Name, 6),
vbUpperCase) <> "SOLVER") Then
Application.VBE.ActiveVBProject.References.AddFromFile
AddIns(i).FullName
End If
Else
MsgBox Prompt:="Solver not found. This workbook
will not WORK", Buttons:=vbCritical
End If
MsgBox "finished"
Exit Sub ' Exit Sub to avoid error handler.
ErrorHandler: ' Error-handling routine.
MsgBox Prompt:="Error in Button2_Click() = " + Str
(Err.Number) + Error(Err.Number) + " Please report to
Analytical Engines", Buttons:=vbCritical
Resume Next ' Resume execution at line after error
End Sub
environment running a macro under Excel 2003 on Windows
XP Professional. The same macro runs fine under Excel
2000 on Windows 2000 which I think does indicate that
this is a genuine error in the VBA environment.
I'm using the code below to check if there is a reference
to the Solver addin. If there isn't a reference, the code
adds the reference. This works fine the first time, but
gives an "already defined" error if run again. I would
expect the code to correctly determine that the reference
already exists and exit the subroutine without attempting
to define the already existing reference - and indeed
this is the case on Excel 2000 on Windows 2000 - but it
is failing on the PC running Excel 2003 and Windows XP
Professional.
Interestingly - and I think this is relevant - the
ActiveVBProject and VBProject are both shown as "VBA
Project" the first time the code is run but the
ActiveVBProject changes to "SOLVER" for subsequent calls
to the code when the error message appears.
So to produce the error on the PC running Excel 2003 and
XP Pro I uncheck the reference to Solver in the VBA
editor, quit Excel completely, start Excel by double
clicking the spreadsheet in Explorer and click the button
that calls the code. The code works fine the first time
but gives the error on subsequent calls.
Does anyone know how I go about trying to get MS to fix
this problem? I've rung local support who say that for
$50 I can speak to an MS professional who I guess woudl
verify what I'm saying and start the bug report process.
Does anyone know if this process is likely to be
fruitful? Or do MS employees monitor these newsgroups?
(And maybe I can save my $50 )
Cheers
David
Code:
Sub Button2_Click()
On Error GoTo ErrorHandler ' Enable error-handling
routine.
MsgBox Prompt:="VBProject name is " +
ThisWorkbook.VBProject.Name, Buttons:=vbCritical
MsgBox Prompt:="ActiveVBProject name is " +
Application.VBE.ActiveVBProject.Name, Buttons:=vbCritical
i = 1
Do Until ((i = AddIns.Count) Or _
(StrConv(Left(AddIns(i).Name, 6),
vbUpperCase) = "SOLVER"))
i = i + 1
Loop
If (StrConv(Left(AddIns(i).Name, 6), vbUpperCase)
= "SOLVER") Then
AddIns(i).Installed = True
j = 1
Do Until (j =
Application.VBE.ActiveVBProject.References.Count Or _
(StrConv(Left
(Application.VBE.ActiveVBProject.References(j).Name, 6),
vbUpperCase) = "SOLVER"))
j = j + 1
Loop
If (StrConv(Left
(Application.VBE.ActiveVBProject.References(j).Name, 6),
vbUpperCase) <> "SOLVER") Then
Application.VBE.ActiveVBProject.References.AddFromFile
AddIns(i).FullName
End If
Else
MsgBox Prompt:="Solver not found. This workbook
will not WORK", Buttons:=vbCritical
End If
MsgBox "finished"
Exit Sub ' Exit Sub to avoid error handler.
ErrorHandler: ' Error-handling routine.
MsgBox Prompt:="Error in Button2_Click() = " + Str
(Err.Number) + Error(Err.Number) + " Please report to
Analytical Engines", Buttons:=vbCritical
Resume Next ' Resume execution at line after error
End Sub