View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Excel Analysis ToolPak - Bug when installed from Code

Hi Philip,

Try changing:

Sheets(1).Select
to:
ThisWorkbook.Sheets(1).Select

(or Workbooks("YourBook.xls").Sheets(1).Select is you aren't selecting a
sheet located in the same workbook where the code is running in).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"pc" wrote in message
oups.com...
I have written some code which generally does exactly what I want it
to. However, when a new user runs it for the first time, they get a
400 error with no explanation, just a red cross.

I can repeat their experience by unchecking Analysis ToolPak and
Analysis ToolPak - VBA from Tools Add-Ins, and then re-opening the
spreadsheet. If I step through the code though, the error does not
occur.

I have removed the majority of my code, to try to establish where the
bug occurs, and I have found that even the few lines below will
reproduce the same error.

Sub Workbook_Open()

AddIns("Analysis ToolPak").Installed = True
AddIns("Analysis ToolPak - VBA").Installed = True

Sheets(1).Select

End Sub

It appears that I cannot select a worksheet after the Analysis ToolPak
is installed by code. I use Excel 2000 / Windows 2000 at home and
Excel 2002 / Windows XP at work, but both set-ups give me the same
problem.

I would be most grateful for any assistance on this. Many thanks in
anticipation.

Philip Clarke