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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 7
    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


     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT