Hello,

I'm new to VBA programming and am having difficulty with using the Analysis Toolpak Add-in. First some background...

I have set the reference to atpvbaen.xls and this reference appears in my project tree. I'm working with Excel 2004 on a Mac.

If, for example, I want to execute the histogram function, I use the following code and everything works fine.

sub testproc()
   Addin("Analysis Toolpak").Installed = True
   Addin("Analysis Toolpak - VBA").Installed = True
   Application.Run "'Analysis Toolpak - VBA'!Histogram", Worksheets("Statistics").Range("$C$2:$C$16"), _
     Worksheets("Statistics").Range("$C$18"), , False, False, False, False
End sub()
Where I run into trouble is when I try to implement this into a UserForm. Here's the code I'm using (with some non-vital parts stripped out):

Private Sub MakeHistoButton_Click()
' Variables are declared here

   ThisWorkbook.AddIns("Analysis Toolpak").Installed = True
   ThisWorkbook.AddIns("Analysis Toolpak - VBA").Installed = True
    
   For Each WrkSht In ActiveWorkbook.Worksheets
      If WrkSht.Name = HistoSheetName Then
         MsgBox "Worksheet " & HistoSheetName & " already exists."
         Exit Sub
      End If
   Next WrkSht

   Worksheets.Add.Name = HistoSheetName
    
' Some code to initialize variables has been deleted....
            
   Application.Run "'Analysis Toolpak - VBA'!Histogram", Worksheets("Statistics").Range("$C$2:$C$16"), _
      Worksheets("Statistics").Range("$C$18"), , False, False, False, False

End Sub
When I try to execute this code through the UserForm, it completes without error, but the Histogram function doesn't do anything. I can put a MsgBox statement before and after the Histogram statement and both dialog boxes display correctly.

So, what went wrong when I went from a stand-alone sub to the private Userform sub?

Thanks for any help on this... I've been searching the forums all weekend trying to find an answer.
-Chad