AppleScript Excel - Copy value of cells into variables

I am super new to AppleScript, so please excuse me if I am not good at explaining what I am trying to do. I have an Excel file that has 12 columns and X rows, I need to have B2/C2/D2/etc copied into variables but have the column be a variable instead of a static number so I can write a loop to get all the rows, etc. Here is what I have now, and I know this is far from being correct.
copy value of cell "B2" to varRow
I have tried something crazy like this:
copy value of column colSection of row intRow to varSection
But that just throws up an error saying the object i am trying to access does not exist. I set the ColSection to "B" and intRow to 2, so I thought it would work. Any ideas or advice I am open! Thanks!

The following should give you the idea:
tell application "Microsoft Excel"
activate
make new workbook
set myCol to 3 -- the starting column
set myBgnRow to 2 -- the starting row
set myString to "Hello World" -- characters to be inserted into sheet as sample values
set myChar to 1 -- Points to first character ("H")
set myEndRow to myBgnRow + (length of myString) - 1 -- the ending row
-- Now put some values into the cells
repeat with myRow from myBgnRow to myEndRow
select (cell myCol of row myRow of active sheet)
tell cell myCol of row myRow
set value to character myChar of myString
end tell
set myChar to myChar + 1
end repeat
-- now get the values back out
-- note that this is using same myBgnRow and myEndRow as above
repeat with myRow from myBgnRow to myEndRow
select (cell myCol of row myRow of active sheet)
tell cell myCol of row myRow
set myVal to value
end tell
display dialog (myCol as text) & "," & (myRow as text) & " " & myVal
end repeat
end tell

Similar Messages

  • Applescript excel copy paste repeat...

    I'm trying to set up a simple applescript to copy a cell and paste it repeatedly down the column to the last record.
    Can some one help?
    The closest I could find is this:
    tell application "Microsoft Excel"
      copy range range "I1"
      paste special range "I2:I5" what paste values
    end tell
    This works, but I need the script to determine the number of rows with data and paste that many times.

    Glad to help!
    A few things to add:
    1.  You only need a tell...end tell for the whole script as you're only addressing the one app
    2.  It would be useful to enclose the whole of the script (inside the tell Excel) in the
              tell active sheet of active workbook ... end tell
    construction.
    3.  At the end you can substitute the copy/paste special with:
              set (value of range ("F2:F" & rowCount)) to (get value of range ("E2:E" & rowCount))
    4. If you do have a header row, then the following changes in the concatenation section (but, I suppose, given that it's going to be deleted it doesn't really matter!)
      set formula of cell "E2" to "=(IF(ISBLANK(D2),,C2&\" \"&D2))"
              fill down range ("E2:E" & rowCount)
    It should end up looking like this:
    tell application "Microsoft Excel"
              tell active sheet of active workbook
      -- remove unneeded columns
                        set mycolumns to range "M:ZZ"
      delete mycolumns
                        set mycolumns to range "D:G"
      delete mycolumns
                        set mycolumns to range "A:A"
      delete mycolumns
      -- Insert 2 columns to work with
      insert into range column 5
      insert into range column 5
      --contencate addresses from C&D into E
                        set formula of cell "ZZ1" to "=MATCH(REPT(\"z\",50),D:D)"
                        set rowCount to get value of cell "ZZ1" as integer
                        set value of cell "ZZ1" to ""
                        set formula of cell "E2" to "=(IF(ISBLANK(D2),,C2&\" \"&D2))"
                        fill down range ("E2:E" & rowCount)
      -- copy a Contencated address values to column F and delete columns C, D, E
                        set (value of range ("F2:F" & rowCount)) to (get value of range ("E2:E" & rowCount))
      delete column "C:E"
              end tell
    end tell

  • *SELECT: How to select value from cube into variable?

    Hi,
    I have an application that need lots of complex calculations.  Currently I am facing problem in retrieving a value from BPC application/database (BW cube) into a script logic local variable.  Let's say the application has  these  following dimensions
    1.  FYPD ( fiscal yr period. 200901, 200902 etc)
    2.  REGION ( A, B , C , D etc)
    3.  PRODUCT(Product ID)
    4.  VERSION ( ACTUAL, FORECAST etc)
    5.  AMOUNT (Sales Amount, signed data )
    Now I need to extract the sales amount into a local valriable where REGION = "A" and  PRODUCT = "SMK-1234" and FYPD = "200905"  and VERSION = "ACTUAL"
    What's should be the equivalent SELECT command? I tried but could not figure out. Any help?
    Regards
    DipM

    Hi DipM,
    There isn't really a concept of local variables for values in script logic. Instead, you'll want to use *WHEN, *LOOKUP, or MDX statements.
    For example, this will copy the value you mention into the PLAN version:
    *WHEN REGION
    *IS A
    *WHEN PRODUCT
    *IS SMK-1234
    *WHEN FYPD
    *IS 200905
    *WHEN VERSION
    *IS ACTUAL
    *REC(FACTOR=1,VERSION=PLAN)
    *ENDWHEN
    *ENDWHEN
    *ENDWHEN
    *ENDWHEN
    See *WHEN ([link|http://help.sap.com/saphelp_bpc70sp02/helpdata/en/36/339907938943ad95d8e6ba37b0d3cd/frameset.htm]) and *REC ([link|http://help.sap.com/saphelp_bpc70sp02/helpdata/en/25/8d51050c43496887ddff88f13e5f1a/frameset.htm]) documentation for more.
    As mentioned, you can also use *LOOKUP or MDX statements to look up values and drive calculations in *REC(EXPRESSION=....) statements. This functionality is outlined in the SP02 documentation addendum ([link|http://service.sap.com/~form/sapnet?_SHORTKEY=00200797470000088146&_SCENARIO=01100035870000000202&]).
    In the MS Version of BPC, there is a concept of local MDX variables that work with the specialized *GO script logic statement. This statement is not available in the Netweaver version.
    Ethan

  • Pasting spreadsheet cells into a new form with the wizard ???

    I must be missing something here. Whenever I try to paste new cells from a spreadsheet into a new form using the new form wizard the 'finish' button doesn't turn active. It's like Livecycle isn't aware that spreadsheet cells have been copied to the clipboard.
    When I try to do it manually and create a new form then copy and paste cells into the form I get a grey image (icon?) that is supposed to repesent something, but I don't know what. It is definitely not spreadsheet cell information.
    Is it because I'm using Office 2000? Has anyone successfully done this?

    I checked in the LC ES help file and it indicates that the spreadsheet option works with 2003 and above. So perhaps it is related to my outdated software.
    Thanks for all your help, internet! :P

  • Applescript. Copy filtered cells in Excel

    I have a task for Applescript to filter Excel cells based on one criteria "NEW" in column "F" and then copy the filtered cells to a new spreadsheet (new file). I succeeded in filtering the data but now I can't figure out how to copy the result and paste it to the new Excel file. I can not manually define range because the filtered data will be different all the time, so I need automated way to identify the filtered range, select, copy and paste in into new CSV file. Thats what I have so far:
    tell application "Microsoft Excel"
              set myFile to "Macintosh HD:Users:JustDo:Desktop:AppleScript:Template.xlsx"
              set new_book to open workbook workbook file name myFile
              autofilter range range "A1:F1" field "6" criteria1 "NEW"
    end tell
    Thanks for your help

    Hi,
    JustDoItNow wrote:
    So, basically I would like to not to select rows above filter arrows and select everything below the filter rows.
    Thanks
    Ok,
    set tRow to missing value
    tell application "Microsoft Excel"
          set myFile to "Macintosh HD:Users:JustDo:Desktop:AppleScript:Template.xlsx"
          set new_book to open workbook workbook file name myFile
          autofilter range range "A1:F1" field "6" criteria1 "NEW"
          -- if you have only one list, remove the repeat and use this line --> set tRow to first row index of range object of list object 1 of active sheet
          repeat with tListObj in (get every list object of active sheet) --get first row index of the top list
                first row index of range object of tListObj
                tell the result to if tRow is missing value or it < tRow then set tRow to it
          end repeat
          tell active sheet
                set {tCol, lastCell} to {first column index, last cell} of used range
                set newRange to (get address of cell tRow of column tCol) & ":" & (get address of lastCell)
                select range newRange
          end tell
          copy range selection
    end tell

  • Need help modifying Applescript to copy "Spotlight Comments" into file

    Hello all,
    I have a very large batch of images of Leonardo da Vinci's notebooks. I used the "Spotlight Comments" field of each file to save information about the notebook page depicted in each image:
    Well, I had to modify each image in Photoshop and when I saved the files, Photoshop of course didn't retain the Spotlight Comments. Now, before I modified the images, I duplicated the directory, so I have a copy of all of the images that retain their Spotlight Comments field with each image's information. What I want to do is copy the text from the Spotlight Comments field of the original files and either paste this text into the Spotlight Comments field of the modified files (which are in a different directory, but retain the same filenames as the originals), or at least copy the text from the Spotlight Comments field of the original files and paste each block of text into a txt file with a couple of blank lines in between each entry, so that I can manually copy/paste the citations into the modified image's Spotlight Comments fields.
    I successfully used this Applescript:  https://discussions.apple.com/message/6741062#6741062
    to get the Spotlight Comments from the original files, but it displays them one by one in pop-up dialog boxes and because I have almost a thousand images it is extraordinarily wearisome to copy the text from each pop-up, paste it into a text file, make two blank lines, click "OK" in the pop-up to get the next one...
    Can anyone suggest how I can modify the code I have to tell the Finder to copy the contents of each pop-up and paste them into a single text file with a couple of blank lines between each entry?
    I have the barest, most rudimentary knowledge of Applescript, which is why I'm asking if one of the wizards here can help me modify or write an Applescript to do what I need to do.
    Thank you so much!
    BTW, here is the code from the aforementioned discussion that gets the Spotlight Comments from files. I made into an Applescript application using Automator:
    tell application "Finder"
    repeat with tItem in input
    set (comment of tItem) to (text returned) of (display dialog "Spotlight Comment: " default answer (comment of tItem as string))
    end repeat
    end tell

    Hi,
    Evan Izer wrote:
    Now, before I modified the images, I duplicated the directory, so I have a copy of all of the images that retain their Spotlight Comments field with each image's information. What I want to do is copy the text from the Spotlight Comments field of the original files and either paste this text into the Spotlight Comments field of the modified files (which are in a different directory, but retain the same filenames as the originals)
    This script does exactly that:
    set sFolder to (choose folder "Select folder wich contains original images.") as string
    set dFolder to choose folder "Select folder wich contains modified images."
    tell application "Finder"
          repeat with tItem in (get document files of dFolder)
                set origFile to sFolder & (get name of tItem)
                if file origFile exists then
                      set origComment to comment of file origFile
                      set comment of tItem to origComment
                end if
          end repeat
    end tell

  • Applescript returns incorrect value with blank cell

    Imagine there is a column of numbers, some which might have the value 0.0 and some which are blank. Imagine wanting to append a data set at the first blank cell using Applescript. As Applescript is currently implemented in Numbers, this is not possible. See the following test.
    1. In Numbers, create a new blank spreadsheet.
    2. Select cell "A1".
    3. Format as text.
    4. Execute the following line of Applescript,
    tell application "Numbers" to get value of cell "A1" of table 1 of sheet 1 of front document
    It returns "0.0".
    I would expect a return "" since it is a empty cell formated as text, no less.
    Because of this, there is no way to find a blank cell since a blank cell returns a value of 0.0 which might be a valid entry.
    Anyone have any ideas for a work around?

    The value of a blank (empty) cell IS zero.
    The value of a cell containing a string whose length is zero contains "".
    Given that, I will post a report because I'm not sure than the value returned in AppleScript is the good choice.
    In AppleWorks for a blank cell, the returned value was "".
    Yvan KOENIG (from FRANCE dimanche 11 janvier 2009 16:31:35)
    +Your tracking number for this issue is Bug ID# 6487875.+
    Hello
    +(1) May I know if the fact than+
    +set v to value of cell "B12"+
    +returns 0.0 when the cell is blank is the designed result.+
    +In AppleWorks in this case, we are accustomed to get an empty string.+
    +(2) In version 1, a cell containing an empty string was accepted in an arithmetic operation.+
    +In version 2, it is rejected.+
    +Is it a design choice or is it a bug ?+
    +Your tracking number for this issue is Bug ID# 6487879.+
    Hello
    +In Numbers, as long as we are referencing cells of the current row (200 for instance), we may use short references like:+
    =(BC)*(DE)
    +When we save as iWork '08 document, the formula is expanded as+
    =(B200C200)*(D200E200)
    +Is it a design choice or a bug ?+

  • Help writing a excel macro to do a copy of 4 cells and paste transpose. I need to loop the copy and paste through 6900 rows of data.

      I need help writing a excelmacro to do a copy of 4 cells and paste transpose.  I need to loop the copy and paste through 6900 rows of data.  I started the macro with two rounds of copying & paster transposed but I need help getting it
    to loop through all rows.  Here is what macro looks like now.
        Range("I2:I5").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("J2").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
        Range("I6:I9").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("J6").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
    End Sub

    Thanks Jim for the solution above.
    Hi Brogents,
    Thanks for posting in our forum. Please note that this forum focuses on questions and feedback for Microsoft Office client. For any
    VBA/Macro related issues, I would suggest you to post in the forum of
    Excel for Developers, where you can get more experienced responses:
    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Select values from table%ROWTYPE variable into a cursor

    I have a stored procedure which has an OUT parameter of table1%ROWTYPE.
    In future we might have to add more OUT parameters of table2%ROWTYPE etc. But at any point of time only one will have values.
    So instead of having table%ROWTYPE as OUT parameter, can I send these single row ( with variable values) in a cursor, so that declaration part atleast will not change.
    Is it possible to select values from table%ROWTYPE variable into a cursor.
    cursorOUT IS
    SELECT * FROM varREC;
    where varREC is table.ROWTYPE variable.
    Or which is the better solution in this situation.
    Thanks.

    SQL> var a refcursor
    SQL> declare
      2   bb emp%ROWTYPE;
      3  begin
      4   select * into bb from emp where rownum = 1;
      5   open :a for select bb.ename ename, bb.empno empno from dual;
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> print a
    ENAME                                 EMPNO
    SMITH                                  7369Rgds.

  • Trying to get sysdate- 2yrs and sysdate+2yrs value into variable

    Hi,
    iam Trying to get sysdate- 2yrs and sysdate+2yrs value into variable.But facing the following issue. Please help me out .
    Error :
    p_start_date := select add_months(max(sysdate), -24) from dual;
    ERROR at line 6:
    ORA-06550: line 6, column 25:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null <an identifier>
    <a double-quoted delimited-identifier> <a bind variable>
    continue avg count current exists max min prior sql stddev
    sum variance execute forall merge time timestamp interval
    date <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternat
    ORA-06550: line 7, column 3:
    PLS-00103: Encountered the symbol "P_END_DATE"
    Code
    declare
    p_start_date date;
    p_end_date date;
    begin
    select add_months(max(sysdate),-24) into p_start_date from dual;
    dbms_output.put_line('p_start_date' |p_start_date);
    dbms_output.put_line('p_end_date' | p_end_date);
    end;

    Hi, try:
    SQL> declare
      2 
      3  p_start_date date;
      4  p_end_date date;
      5 
      6  begin
      7 
      8  select add_months(sysdate,-24) into p_start_date from dual;
      9  select add_months(sysdate, 24) into p_end_date from dual;
    10 
    11  dbms_output.put_line('p_start_date: ' ||to_char(p_start_date, 'dd-mm-yyyy hh24:mi:ss'));
    12  dbms_output.put_line('p_end_date: '   ||to_char(p_end_date, 'dd-mm-yyyy hh24:mi:ss'));
    13  end;
    14  /
    p_start_date: 14-04-2007 17:41:34
    p_end_date: 14-04-2011 17:41:34
    PL/SQL procedure successfully completed.

  • Setting cell into char in ole2 excel???

    I'am making a program that have an output in excel form. I use ole2. My problem is: i have difficullty in setting a cell into character or text. Because when i retrieve data : 0211 it will appear 211. I want the 0 also could appear. The only way to do it is to set the cell into char/text...and i dont know the what the syntax are...please could anybody help me....

    From my experience the best way to get a starting point is to record a macro and apply it to forms.
    In this case this would lead to a macro like this (I have Office 2003):
    Range("C1").Select
    Selection.NumberFormat = "@"
    That means you need a selection object and set the "NumberFormat" property to "@".
    Something like
    ole2.set_property(vselection,'NumberFormat','@');
    Gerald

  • How to copy the table datas into an  open office excel file .

    Hello All ,
    I have a form which contains several pages . Each page contains some tables in it . How can we copy each table datas into an open office execl files ??
    I mean there will be several excel files each file corresponds to a particular table in the form. I am using LiveCycle Designer ES 2 . in Windows XP.
    Thanks
    Bibhu.

    Hi Bibhu,
    Here is a screenshot of exporting the form data to XML:
    I have not imported XML into Excel, but I know that Excel 2007 has tools for this in the Developer tab. I don't have Excel 2007 on this machine, so I can't get screenshots. However using Acrobat you can merge the XML file into a spreadsheet, using the same menu Forms > Manage Form Data > Merge Data Files into Spreadsheet.
    In addition you can set up a data connection to the spreadsheet. However this will only work in a Windows environment and you need to share the OLEDB data connection with all users. In addition if you Reader Enable the form with Acrobat, the data connection will not work.
    So on balance if you want to get data to a spreadsheet I would recommend export XML.
    Hope that helps,
    Niall

  • Inserting a variable value from querystring into captivate and out again

    I am using Captivate 4 on a server that uses ASP and I use FrontPage to write my ASP pages.
    I have a database built and hosted at the same location as my captivate file.  I used to launch my captivate and then have the user continue to a form page, enter their information and submit to the database.  This all worked great.
    Now I need to capture completion of several captivate files (modules).  So I want an ASP page that allows the user to see what modules are done (I use a request form to search my database).  It works great.  It comes back and tells the user what needs to be taken.  They, on that same page, can then select the module to complete next (I have the request querystring added to the URL that launchs the captivate file (I changed it from a html page to an asp page).
    It launches fine but I can't figure out how to get that request querystring into captivate as my variable value.  question 1
    Then after that is figured out I need to know how to pass that variable back to an ASP page that will contain form questions that will then travel to the database.  (Thus giving them credit for that module).  question 2
    Any help would be great.  I am not very good at code, but trying.  My database is Access.

    So you want to pass some data into Captivate? This can be achieved with a Flash Widget and FlashVars. Basically you would be able to launch a Captivate project on www.google.com/myProject?myVariable=1 and then get the value of myVariable into a Flash widget. The Flash Widget could then pass this variable into Captivate be populating a custom variable that you have definied within Captivate. From that point on you would be able to use the variable in your Captivate project. Google for Flash Vars to see what can be done with it.
    As for the other way around - Captivate sending information to your ASP script - that would also require a widget (or perhaps calling a JavaScript function). From the Flash widget you would be able to pass along data from Captivate to an external script and then use it any way you want.
    Hope this points you in the right direction.
    /Michael
    Visit my Captivate blog with tips & tricks, tutorials and Widgets.

  • Transform value into variable

    Hi all. I need to clear a field in a structure, but the problem is that this field is known only during runtime and is contained as a value of another field (lv_need_clear). How can the value be into transformed into variable?
    CONCATENATE 'ls_bapi_' <ls_matdata>-tabname 'x' '-'
    <ls_dd03p>-deffdname INTO lv_need_clear.
    CLEAR  "...???

    u can assign structure too.
    FIELD-SYMBOLS <fs_struc> TYPE ANY.
    ASSIGN (structure_name) TO <fs_struc>.
    check sy-subrc EQ 0.
    then.
    ASSIGN COMPONENT (field_name) OF structure <fs_struct> TO <fs>.

  • Need to validate file Name,split the file name and store the splited values into Variables

    Dear All,
    Below is the my requirement.
    I have a folder, in that folder I have bunch of text files. The file name is below format
    ACA_122_pay_20140430_001
    Initially the file name start with ACA code,groupid,group name and date time stamp. This is the standard structure of file name.
    I want to check each and every file in the folder with this structure. The structure should be standard for all the files. If the structure same for all files I need to get codes form file name. For example
    If you see the below file name, I need to get ACA and put into variable,I need to get 122 and put into variable. For group name and date time needs to put in variable.
    If the file format is not valid state then I need to log exception.
    Let me know if I am not clear.
    Kindly provide the C# code for achieving the above requirement.
    As I am new to .net programming. kindly help me.
    Thanks in Advance,
    Regards,
    Madhava Ganji
    Madhava Ganji

    Hi MadhavaGanji,
    I have post how to validate the file name, header row against definition table which stored the file name and column definition. 
    Take a look and see if this is helpful.
    http://sqlage.blogspot.com/2013/11/ssis-validate-file-header-against.html
    http://sqlage.blogspot.com/

Maybe you are looking for

  • Unrecognized Seagate 320 GB External USB Powered HD

    I just purchased a new 320 GB USB External Hard Drive. It is powered through the USB. My 15" PowerBook G4 does not recognize its existence when I plug it in to the USB port. I have tried both ports. They both work with a mouse. I also plugged the dri

  • Mailbox move during DAG failover is stuck

    I have a DAG setup on exchagne 2010.  I had several mailbox moves going, some in progress and some queued.  The destination mailbox database failed over to a different server.  Now the inprogress and queued moves are stuck and I cant suspend them.  A

  • FM to calculate fiscalyear period from current date

    Experts, Is there any FM which outputs fiscal year period in the format mmm/yyyy when current date is given as input. I need this coz i want to automatically calculate current fiscalyear period for a query variable.. Thanks, DV

  • ITunes keeps Launching since updating iPod/iPad to IOS 5.0

    I upgraded to 10.5 with no issues that I'm aware of.  Last night I began updating my devices to IOS 5.0 and finished up today.  I closed iTunes - and 10 minutes later it opened again.  Closed it - it relaunched.  Did this a number of times - then shu

  • Blackberry Messenger - Chat history request question

    Hi I am a first timer on here, so please be gentle. My daughter uses BBM quite a bit, but has recently been acussed of being involved in something silly.  I have checked the chat history settings, but they are turned off.  So I have now turned them b