Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - Writing Excel Addons
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Writing Excel Addons
By: David Bolton
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2004-12-14

    Table of Contents:
  • Writing Excel Addons
  • Huge Strings are a Huge Mistake
  • Xloper Definition
  • Caution- Recalculation Alert!
  • Getting Values from an Excel Spreadsheet
  • Reading Cell Values
  • Putting values into Excel Cells
  • An example Add-In

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Writing Excel Addons - Getting Values from an Excel Spreadsheet


    (Page 5 of 8 )

    Values can be passed in, in three ways.

    1. As a passed-by-value. Eg =CalcMean(4,5,8); xltypenum or xltypestr.

    2. As a Simple reference, say a cell a1 or range a3:b56. xltypesref.

    3.  As a composite Reference. Basically a collection of disjoint cell references. xltypemref

    The first and the second are the most common. The third is a bit weird and unless really needed, it is better to filter this out. If you want to use it, the input is an array of cell references (type 2), so you have to use each one.

    Excel will filter the data type if you specify it (number, string etc) but if you're expecting a range, then you should fully check the type and ranges of values, reporting errors if appropriate.

    Returning Errors

    Your function must return an lpxloper (type R) if you wish to return Excel Error codes. To set an error in Res (an xloper) just do

    res.xltype := xltypeerr;
    res.val.err := number; // returns following values then just return @res from your function

    Number Excel Err
    0 #NULL
    7 #DIV/0
    15 #VALUE
    23 #REF
    29 #NAME
    36 #NUM
    42 #N/A

    With complicated, many parameter functions I think that standard Excel errors are a little unfriendly, so I strongly suggest a GetlastError() function which returns the last error string. Any function which returns an error should set the error string returned by GetLastError(). This will save users a lot of time when they are using your functions for the first time.

    More Windows Scripting Articles
    More By David Bolton


       · The reason you need to use assembler to pop another parameter off the stack when the...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek