• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Retrieving a "Range" in Excel for storage in a Database
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Retrieving a "Range" in Excel for storage in a Database


  • Subject: Re: Retrieving a "Range" in Excel for storage in a Database
  • From: Stan Cleveland <email@hidden>
  • Date: Wed, 08 Jul 2009 09:47:08 -0700
  • Thread-topic: Retrieving a "Range" in Excel for storage in a Database

On 7/8/09 4:04 AM, "Frank Renner" wrote:

> what is the best way to retrieve a "Range object" for connecting it to
> a database?
>
> For Example, if I select cell "F243", I want to use an applescript
> that retrieves something like "F243" that I can store in the database
> and later use again to reference that cell and change it's value using
> "set value of cell "F243" to <ValueFromDatabase>".
>
> Is it possible to use the "name" property of the cell for referencing
> purposes? It is easy to assign a name to a cell, but how can I select
> this cell again by using it's name?

Hi Frank,

An easy mistake to make with Excel is to assume that you must "select" a
cell or range before you can retrieve or change data. When scripting, that's
a bad idea. Just set and get the information directly and leave the GUI out
of the picture. Below is some simple code to get you started.

Note that when retrieving data, the primary three methods involve getting
the formula (the underlying value or actual formula in the cell), the value
(which is generally the result as a numeric value, but can give surprising
results), or the string value (the result converted to a string).

tell application "Microsoft Excel" -- 2008
    -- define name
    set name of cell "F243" to "MyCell"
    -- use name directly
    set formula of cell "MyCell" to 27
    set oldForm to formula of cell "MyCell" -- 27
    -- use name via tell
    tell cell "MyCell"
        set oldVal to value -- 27.0
        set oldStr to string value -- "27"
        set formula to "=25/2"
        set newForm to formula -- "=25/2"
        set newVal to value -- 12.5
        set newStr to string value -- "12.5"
    end tell
end tell

One more tidbit--you can give the same cell or range more than one name, any
and all of which can be used to reference the data therein. Also, the name
property reflects the name function accessed in the GUI from the menu
command "Insert > Name > Define...".

HTH,
Stan C.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Retrieving a "Range" in Excel for storage in a Database
      • From: Paul Berkowitz <email@hidden>
References: 
 >Retrieving a "Range" in Excel for storage in a Database (From: Frank Renner <email@hidden>)

  • Prev by Date: How to determine if a folder exists on a system?
  • Next by Date: Re: How to determine if a folder exists on a system?
  • Previous by thread: Retrieving a "Range" in Excel for storage in a Database
  • Next by thread: Re: Retrieving a "Range" in Excel for storage in a Database
  • Index(es):
    • Date
    • Thread